Used for changing the value of an element in a DOM.
There are two ways of using the fm:assign function. The first one initialises the element you are referring to if it doesn’t already exist:
<fm:assign initTarget=":{root}/A" textValue="PRIMARY_DATA"/>
The other only assigns the value to an existing target element:
<fm:assign setTarget=":{root}/A" textValue="PRIMARY_DATA"/>
As you can see you must supply a target (that is initialised or just set) and a value. This value can be a text value, in the above example the target will be set to “PRIMARY_DATA”. You can also use an XPath expression in the following way:
<fm:assign initTarget=":{root}/A" expr=":{root}/B"/>
Whenever you are initialising data, using fm:init or fm:assign, if you target a node in a tree structure that does not exist, FOX will initialise all its ancestors at the same time. See Example 1 below.
When you are assigning a value using a setTarget and an XPath, the :{assignee} context refers to the original value of the element. This means you can use it in your assignment. See Example 2 below.
The following assignment is used in a module to create a CONTEXT structure. By using this assignment the CONTEXT element is created, as is the SUBJECT sub element that in turn has a sub element called REF_ID1. Contexts are covered in other worksheets.
<fm:init target=”/*/CONTEXT/SUBJECT/REF_ID1”/>
<fm:assign setTarget=”/*/CONTEXT/SUBJECT/REF_ID1”
expr=”sring(concat(:{params}/P_ID), ‘OU’)”/>
The REF_ID1 element will get the value of the XPath which is concatenating the P_ID element in the :{params} DOM with the letters ‘OU’.
You can use the :{assignee} context to compute the new value when you assign a value to an element:
<fm:assign initTarget=”/*/ITEM/PRICE”
expr=”round(:{assignee} div 100 * 105 * 100) div 100”/>
You can use :{assignee} multiple times within an fm:assign statement:
<fm:init target=”/*/EMPLOYEE_LIST/EMPLOYEE/FULLNAME”/>
<fm:assign setTarget=”/*/EMPLOYEE_LIST/EMPLOYEE/FULLNAME”
expr=”string(concat(:{assignee}/../FORENAME, ‘ ’,
:{assignee}/..SURNAME))”/>
Please use your XX_ORDERMODULE (where XX are your initials) file for the following exercises.
Create an action named “action-change” that is a button. This action should use an fm:assign to increase the UNIT_PRICE and PRICE elements of all items in your Order List by 15 percent.
In the entry-theme, for each item in your Order List, initialise an element named AVAILABLE that has the value ‘true’.
Add an assign to action-change that will set the AVAILABLE element to ‘false’ for all items where the ordered quantity is higher than five.