Example Constants
|
PLEASE NOTE
When writing XML, please be aware that XML is case sensitive. If a Constant is defined using XML code with incorrect upper or lower case, it will not work.
For example:
OK: <Function name="Add">
WRONG: <Function Name="Add">
|
Formula expression constants: Examples for DATE based constants
The following examples can be used for example to calculate:
- The date which is three days from now.
- The first or last
- Day of the Year
- Day of the current Month
- Day of a current Week
// Add 3 days to today's date
<Function name="Add">
<Value type="date" value=".SYS_TODAY"/>
<Value type="date" value="3"/>
</Function>
//Subtract 7 days from today's date
<Function name="Subtract">
<Value type="date" value=".SYS_TODAY" />
<Value type="date" value="7" />
</Function>
//Calculate the first day of the CURRENT WEEK (which will be the Monday of the current week)
<Function name="StartOfWeek">
<Value type="date" value=".SYS_TODAY" />
</Function>
//Calculate the last day of the CURRENT WEEK (which will be the Sunday of the current week)
<Function name="EndOfWeek">
<Value type="date" value=".SYS_TODAY" />
</Function>
//Calculate the last day of the FOLLOWING WEEK (which will be the Sunday of the current week)
<Function name="Add">
<Function name="EndOfWeek">
<Value type="date" value=".SYS_TODAY" />
</Function>
<Value type="date" value="7" />
</Function>
// Calculate the first day of the CURRENT MONTH
<Function name="StartOfMonth">
<Value type="date" value=".SYS_TODAY"/>
</Function>
// Calculate the last day of the CURRENT MONTH
<Function name="EndOfMonth">
<Value type="date" value=".SYS_TODAY"/>
</Function>
// Calculate the first day of the CURRENT YEAR
<Function name="StartOfYear">
<Value type="date" value=".SYS_TODAY"/>
</Function>
// Calculate the last day of the CURRENT YEAR
<Function name="EndOfYear">
<Value type="date" value=".SYS_TODAY"/>
</Function>
Formula expression constants: Examples for Calculations
// Add 365 days to a field “Expiry Date”
<Function name="Add">
<Value type="date" value="bms_9999999_8435" />
<Value type="date" value="365" />
</Function>
Note: bms_9999999_8435 is the bms_id of the field that can be got from Component Management
// Subtract pi from the field "somenumber"
<Function name="Subtract">
<Value type="attrib" value="somenumber"/>
<Value type="decimal" value="3.14"/>
</Function>
"Order" and "Reverse" operators in Locator- Based Constants – returning the highest/lowest value from a component
A prime example of using the "Order" and "Reverse" operators in Locator-Based Constants is a constant that returns the most recent Incident Date from the Incident component.
You can use these constants in API calls (Rest Callouts/Data Imports via API) to, for example, request for data where a certain date is greater than the "the most recent Incident Date from the Incident component".
ID: LATEST_INCIDENT Name: Most Recent Incidents Type: Date Date Format: yyyy-MM-dd Value:
<Locator type="obj.com.bmssolutions.COMPONENT.bms_9999999_104">
<Order name="bms_9999999_1020" reverse="true"/>
<Attribute>bms_9999999_1020</Attribute>
</Locator>
In the API URL, this can refer to the constant like below:
https://myserver/ehss/odata/incident?$filter=date(incident_date) gt |LATEST_INCIDENT|
When the import processes the URL, it will substitute the constant with the Incident date of the most recent Incident records.
https://myserver/ehss/odata/incident?$filter=date(incident_date) gt 2023-06-15
Formula XML
A formula is defined as:
<%Operation%>
%Value%
%Value%
…
</%Operation%>
or
<%Operation type="%type%" value="%constant%|%field name%"/>
where:
%Operation% is one of those listed in the topic: Functions and Operations.%Value% can be another formula, or be an explicit value of the form: <Value type="%type%" value="%constant%|%field name%"/> %type% is one of the types listed in the topic: Types.%constant% is a numeric, date, text or system constant.%field name% is the name of a field relevant to the object.
Condition XML: Example
// incidents that have happened in the last 24 hours
<Condition op="AND">
<Condition op="LE" entries="true" lhs="bms_9999999_2970" rhs=".NOW" type="datetime" />
<Condition op="GE" entries="true" lhs="bms_9999999_2970" type="datetime">
<Function name="Subtract">
<Value type="date" value=".NOW"/>
<Value type="date" value=":24:00"/>
</Function>
</Condition>
</Condition>
|