Today let’s put spotlight on the item fields. First we will see how to access each field from the Item object. Then we will go through all field types and find the corresponding value type in scripting for each of them.
Access Field Value With Field ID
When an item is loaded, all its field properties have been put into it with their Field ID as the key. So to access the value of each field, we just need acquire it from the Item variable directly using the field ID. For example:
var name = item.NAME; // read the value of NAME field from owner item
item.AGE++; // increase the value of AGE field in owner item by one
PLM scripting is case sensitive, and Field IDs are always in upper case, so neither “item.name” nor “item.Age” will work in this example. Field ID is not editable and must be unique to the workspace. It doesn’t have to be the same as the field name. So if you are not sure about the field ID, you can find it in the field edit window. [Administration -> Workspace Manager -> workspace –> Item Details Tab –> Edit a field by click the pencil icon]
Field Type vs. Data Value Type
As the above screenshot shows, there are many different field types provided. The different field type has different value type in scripting, and some of the field values are editable but some are read-only. To make things clear I put all these information into below table:
Field Type | Value Type | R/W |
Auto Number | String | Read-only |
Single Line Text | String | R/W |
BOM UOM Pick List | String | R/W |
Image | String | Read-only |
URL | String | R/W |
String | R/W | |
CSV | String | R/W |
Flash | String | Read-only |
Paragraph | String | R/W |
Paragraph w/o Line Breaks | String | R/W |
Integer | Number | R/W |
Float | Number | R/W |
Money | Number | R/W |
Date | Date | R/W |
Check Box | Boolean | R/W |
Derived | Same as source field | Read-only |
Single-Selection1 Item-Pick-List2 | Item | R/W |
Multiple-Selection Item-Pick-List | Array of Item | R/W |
Filtered Item-Pick-List | String | R/W |
Single-SelectionValue-Pick-List3 | String | R/W |
Multiple-Selection Value-Pick-List | Array of String | R/W |
Footnotes:
- The Single-Selection here includes the selectable pick list field types of: “Radio Button”, “Single Selection”, “Show first value as default”, “Retains Last Saved Label”, “With search Filter” and “Latest Version”.
- Item-Pick-List is a list of item records from a workspace, which can be chosen in the pick list creation form. Single-selection item pick list returns a single Item object. Multiple-selection item pick list returns an Array of Item objects.
- Value-Pick-List is a list of String values defined by user. Single-selection returns a single String value. Multiple-selection returns an Array of String values.
-- Michal