Variable Examples
These example calculated attributes are written to use the data defined in the following tables.
For function syntax information on and more detailed use cases, refer to the Variable Functions documentation here.
The examples below assume a setup including these attributes and products:
ATTRIBUTE Type |
ID |
Name |
---|---|---|
Text-validated product attribute |
TEXT1id |
TEXT1 |
PRODUCTS ID |
Name |
Parent |
TEXT1id |
---|---|---|---|
P-family-id |
P-family |
Product hierarchy root |
family value |
P1id |
P1 |
P-family-id |
p1 value |
P2id |
P2 |
P-family-id |
p2 value |
P3id |
P3 |
P-family-id |
p3 value |
After creating the data above, copy and paste any of the Value Template text below into the Function Editor, select the object with the defined data, and click the Evaluate button to display the Result.
Value Template |
Object |
Result |
---|---|---|
{txt:=prodval('TEXT1id'), pos:=find('p3', txt) } if(pos='N/A', 'no P3', replace(txt, pos, 2, '??')) |
P3 P2 |
?? value no P3 |
{total:=0, loop:=iterate(listconcatenate(1,4,8,13), 'total:=total+item') } concatenate(total) |
{any} |
26 |
Concatenate Function with Variables
Consider a calculated attribute that will concatenate two different attribute values, where they style of each should be different. Use character tags in STEP to format (or style) text attributes. Then convert those tags to either paragraph or character tags for the output media. For information on character tags, refer to Tags here.
The example calculated attribute is written to use an object with the attributes defined in the following table.
Attribute> |
ProductName |
KeyLetter |
Mandatory |
Yes |
No |
Character Tag |
[PN] |
[KL] |
The example calculated attributes below use an object with the attribute values defined in the following table.
|
ProductName |
KeyLetter |
Required Result |
Product1(P1) |
Acme Widget |
A |
[KL]A. [PN]Acme Widget |
Product2(P2) |
Acme Widget |
|
[PN]Acme Widget |
A calculated attribute can produce the same result with or without variables as demonstrated in the table below.
Value Template With Variables |
Value Template Without Variables |
---|---|
{pnnokey := concatenate('[PN]',prodval("ProductName")), pnwkey := concatenate('[KL]',prodval("KeyLetter"), '. [PN]',prodval("ProductName")) } if(exact(prodval("KeyLetter"),''),pnnokey,pnwkey) |
if(exact(prodval("KeyLetter"),''), concatenate('[PN]',prodval("ProductName")), concatenate('[KL]',prodval("KeyLetter"), '. [PN]',prodval("ProductName"))) |
Variables
In this example, two variables allow the actual value template (the last line) to be shorter and more legible to the reader:
- Variable 'pnnokey' calculates the result when no KeyLetter value exists.
- Variable 'pnwkey' calculates when there is a KeyLetter value.
In both examples, testing for a blank value is achieved by using the EXACT function to compare against two (2) single quote marks (') with no spaces between them.
Find Function with Variables
The example calculated attributes below use an object with the attribute values defined in the following table.
|
ProductName(prodname) |
Product1(P1) |
ACME-BP-1001 Super XBP |
A calculated attribute can produce the same result with or without variables as demonstrated in the table below.
Value Template |
Result |
Notes |
---|---|---|
{x := find('-BP-', prodval("prodname")), y := 'Boardroom Projector Series' } if(exact(x,'N/A'),'',replace(prodval("prodname"),x+1,2,y)) |
ACME-Boardroom Projector Series-1001 Super XBP |
The IF function checks if the value of x is 'N/A'
|
Variables
- Variable 'x' finds the position of the text string that will be replaced using the FIND function. In this example, the position of the text '-BP-' within the 'prodname' attribute value is needed. The function returns the numeric value of the position, in this example, 5 is returned since the first dash is at position 5.
- Variable 'y' supplies the replacement text string.