Value rule script

You can write a value rule for each node of a multi-occurring attribute such that a value corresponding to each multi-occurring attribute is generated.

The same value is calculated for every node in a multi-occurring attribute according to the value rule. Following procedure describes how to avoid that and write a value rule, which calculates the value for each corresponding multi-occurring attribute.
Suppose a multi-occurring attribute (Price) has the following structure:
SpecParts
Price 
PartName
Cost
Discount
Wholesaleprice
If Price occurs twice as follows,
Price(0) 
Wheel
32
2 
WholesalepriceA
Price(1) 
Tyre
98
6 
WholesalepriceB
Suppose that the following value rule script is written on Wholesaleprice:
cost = item.getCtgItemAttrib("SpecParts/Price/Cost") ;
discount = item.getCtgItemAttrib("SpecParts/Price/Discount");
res = cost*(100-discount)/100;

The value rule script repeats the same value of Wholesaleprice for every occurrence of Price, which is incorrect because Wholesaleprice is derived from the calculation of cost and discount. For every occurrence of Price, the calculated value of Wholesaleprice must be different.

Alternatively, to route through the multi-attribute tree, retrieve, and set values through EntryNodes, use the following value rule script:

You might set the following script as a value rule on Wholesaleprice:
pnode = entrynode.getEntryNodeParent();
wnode = pnode.getEntryNode("/Cost");
mnode = pnode.getEntryNode("/Discount");
cost = wnode.getEntryNodeValue("/Cost");
discount = mnode.getEntryNodeValue("/Discount");

This script returns the correct value for WholesalepriceB, WholesalepriceA, which depends on the corresponding value of cost and discount for that occurrence.