Converting Values Between Different BOM Attribute Types

This section shows how to convert between fields of different types, for example, how to convert between a text field containing the String 123 and an integer field containing the number 123.

Note: In some cases you can convert between two different types implicitly, without using the factory methods listed in this table. See Implicit Conversions Between Numeric Types
To Type From Type Example Comments
Boolean Text bomField.booleanAttribute =

ScriptUtil.createBoolean(

bomField.textAttribute);

Parameter to createBoolean() should be true or false
Boolean Integer-Signed bomField.booleanAttribute =

(1 == bomField.integerSigned);

 
Boolean Integer-Fixed bomField.booleanAttribute =

bomField.integerFixed.equals(

ScriptUtil.createBigInteger(1));

 
Boolean Decimal Signed bomField.booleanAttribute =

(1.0 == bomField.decimalFloat);

Testing for equality may not give expected result due to floating point inaccuracies, e.g. (14/10==1.4) evaluates to false due to rounding errors
Boolean Decimal Fixed bomField.booleanAttribute =

(bomField.decimalFixed.compareTo(

ScriptUtil.createBigDecimal(1)) == 0);

 
Boolean Date, Time, Datetime,

Datetimetz Duration, ID, URI, Object, Attachment

N/A N/A
Text Boolean bomField.text = bomField.bool; Results in true or false value being assigned.
Text Integer-Signed bomField.text = bomField. intSigned;  
Text Integer-Fixed bomField.text = bomField.integerFixed;  
Text Decimal Float bomField.text = bomField.decimal;  
Text Decimal Fixed bomField.text = bomField.decimalFixed;  
Text Date, Time, Datetime,

Datetimetz

bomField.text = bomField.date;

bomField.text = bomField.time;

bomField.text = bomField.datetime;

bomField.text = bomField.datetimetz;

yyyy-mm-dd

hh:mm:ss

yyyy-mm-ddThh:mm:ss

yyyy-mm-ddThh:mm:ssZ

Text Duration bomField.text = bomField.duration; For example, P12DT3H for 12 days and 3 hours.
Text ID, URI bomField.text = bomField.id;

bomField.text = bomField.uri;

Same value
Text Object, Attachment N/A N/A
Integer Signed Text bomField.intSigned = parseInt(bomField.text);

bomField. intSigned =

parseInt(bomField.text,10);

parseInt() stops at first non-number character. Copes with base.
Integer Signed Integer-Fixed bomField. intSigned =

parseInt(bomField.intFixed.toString());

Goes by a String

Can result in loss of precision

Integer Signed Decimal Float bomField. intSigned =

bomField.decFloat;

Rounds toward 0
Integer Signed Decimal Fixed bomField. intSigned =

parseInt(bomField.intFixed.toString());

Goes by a String
Integer Signed Boolean, Date, Time, Datetime,

Datetimetz,

Duration, ID, URI, Object, Attachment

N/A N/A
Integer Fixed Text bomField.intFixed = ScriptUtil.createBigInteger(

bomField.text);

Using ScriptUtil Factory
Integer Fixed Integer-Signed bomField.intFixed = ScriptUtil.createBigInteger(

bomField.intSigned);

Using ScriptUtil Factory
Integer Fixed Decimal Float bomField.intFixed = ScriptUtil.createBigInteger(

bomField.decFloat);

Rounds towards 0
Integer Fixed Decimal Fixed bomField.intFixed = ScriptUtil.createBigInteger(

bomField.decFixed);

Rounds towards 0
Integer Fixed Boolean, Date, Time, Datetime, Datetimetz, Duration, ID, URI, Object, Attachment N/A N/A
Floating Point Text bomField.decFloat = parseFloat( bomField.text); NaN if starts with non-digit. Or ignores after non-digit, for example, 45z à 45.
Floating Point Integer-Fixed bomField.decFloat =parseFloat(bomField.intFixed.toString()); First converts value to a String and then to a Floating Point. Possible loss of precision.
Floating Point Decimal Fixed bomField.decFloat =parseFloat(bomField.decFixed.toString()); First converts value to a String and then to a Floating Point. Possible loss of precision.
Floating Point Boolean , Date, Time, Datetime,

Datetimetz,

Duration, ID, URI, Object, Attachment

N/A N/A
Decimal Fixed Text bomField.decFixed =

ScriptUtil.createBigDecimal(

bomField.text);

Using ScriptUtil Factory
Decimal Fixed Integer-Signed bomField.decFixed =

ScriptUtil.createBigDecimal(

bomField.intSigned);

Using ScriptUtil Factory
Decimal Fixed Decimal Float bomField.decFixed =

ScriptUtil.createBigDecimal(

bomField.decFloat);

Using ScriptUtil Factory
Decimal Fixed Integer Fixed bomField.decFixed =

ScriptUtil.createBigDecimal(

bomField.text);

Using ScriptUtil Factory
Decimal Fixed Boolean , Date, Time, Datetime, Datetimetz, Duration, ID, URI, Object, Attachment N/A N/A
Date, Time, Datetime, Datetimetz Text bomField.date = DateTimeUtil.createDate(

bomField.text);

bomField.time = DateTimeUtil.createTime(

bomField.text);

bomField.datetime =

DateTimeUtil.createDatetime(

bomField.text);

bomField.datetimetz =

DateTimeUtil.createDatetimetz(

bomField.text);

 
Date, Time, Datetime, Datetimetz Integer, Decimal Float e.g.

bomField.date = DateTimeUtil.createDate(

bomField.intYear, bomField.intMonth, bomField.intDay);

See DateTimeUtil for more factory methods
Date, Time, Datetime, Datetimetz Date, time, Datetime, Datetimetz bomField.datetime = DateTimeUtil.createDatetime(

bomField.date, bomField.time);

See DateTimeUtil for more factory methods
Date, Time, Datetime, Datetimetz Boolean, Fixed Integer, Fixed Decimal, Duration,

ID, URI, Object, Attachment

N/A N/A
Duration Text bomField.duration = DateTimeUtil.createDuration(

bomField.text);

 
Duration Signed Integer, Fixed Integer, Decimal Float, Decimal Fixed bomField.duration = DateTimeUtil.createDuration(

bomField.integerOrDecimal);

Specify duration in milliseconds using any of the 4 numeric sub-types
Duration All other types N/A N/A
ID, URI Text bomField.uri = bomField.text;

bomField.id = bomField.text;

 
ID, URI All other types N/A N/A
Object All Business Objects N/A Can only be assigned an Object attribute or a Business Object
Attachment All Types N/A N/A