Button Click
| Rules and examples |
|---|
|
Rules are client-side scripts (no-code business logic) that are executed when a user of the mobile app interacts with the app. The Button Click rules are executed when a row button is clicked. Rules are managed using the rules editor, usually in Woodford.
Button Click rules are available on the:
- Views
- Forms (requires release 12.2)
- Questionnaires (requires release 14.1)
Button Click variables
- Handled
- If false (default) the standard behavior is executed after the rule. If True, it is skipped.
Handled Assign False
- DirectEdit
- Controls how the changes to the entity are handled (if there are any).
- True and the entity is dirty after the rule executes, the entity is saved to storage (OnSave rule is run).
- False, if a property is changed the ChangeRule is run and the entity is added to the list of dirty entities to be saved on user command.
- Null (not-set, default), changes are ignored.
Example: create a new order or appointment
These two examples, showcase custom buttons on the account form.
First, we click Add button and fill in the name of the button (Click text, Label):
Then, set up a Button Click rule. Changeditem is the button's item binding (set in properties). We create a variable that will be a new instance of order or appointment and assign the customer id from the account. In the end, we open a new appointment/order record.
<?xml version="1.0" ?>
<Workflow e="true" isvalid="true" syntaxVersion="11" version="0">
<branch e="true" info="Create a new appointment button">
<if e="true">
<conditions e="true" op="And">
<condition e="false">
<var>ChangedItem</var>
<op>Equal</op>
<arg>String:Create new appointment</arg>
</condition>
</conditions>
<action>
<definition e="false">
<var>NewAppointment</var>
<func>NewInstance</func>
<type>Entity</type>
<arg>String:appointment</arg>
</definition>
<function e="false">
<var>NewAppointment.regardingobjectid</var>
<func>Assign</func>
<arg>var:Entity.@this</arg>
</function>
<function e="false">
<var>NewAppointment.createdon</var>
<func>SetToday</func>
</function>
<function e="false">
<var>NewAppointment.subject</var>
<func>Concat</func>
<arg>String:Meeting with: </arg>
<arg>var:Entity.primarycontactid</arg>
</function>
<definition e="false">
<var>OpenNewAppointment</var>
<func>Assign</func>
<type>Lookup</type>
<arg>var:NewAppointment.@this</arg>
</definition>
<function e="false">
<var>OpenNewAppointment</var>
<func>OpenForm</func>
<arg>String:</arg>
</function>
</action>
</if>
</branch>
<branch e="true" info="Create a new order button">
<if e="true">
<conditions e="true" op="And">
<condition e="false">
<var>ChangedItem</var>
<op>Equal</op>
<arg>String:Create new order</arg>
</condition>
</conditions>
<action>
<definition e="false">
<var>NewOrder</var>
<func>NewInstance</func>
<type>Entity</type>
<arg>String:salesorder</arg>
</definition>
<function e="false">
<var>NewOrder.customerid</var>
<func>Assign</func>
<arg>var:Entity.@this</arg>
</function>
<function e="false">
<var>NewOrder.createdon</var>
<func>SetToday</func>
</function>
<function e="false">
<var>NewOrder.shipto_country</var>
<func>Assign</func>
<arg>var:Entity.address1_country</arg>
</function>
<function e="false">
<var>NewOrder.shipto_city</var>
<func>Assign</func>
<arg>var:Entity.address1_city</arg>
</function>
<function e="false">
<var>NewOrder.shipto_line1</var>
<func>Assign</func>
<arg>var:Entity.address1_line1</arg>
</function>
<function e="false">
<var>NewOrder.shipto_line2</var>
<func>Assign</func>
<arg>var:Entity.address1_line2</arg>
</function>
<function e="false">
<var>NewOrder.shipto_line3</var>
<func>Assign</func>
<arg>var:Entity.address1_line3</arg>
</function>
<function e="false">
<var>NewOrder.shipto_postalcode</var>
<func>Assign</func>
<arg>var:Entity.address1_postalcode</arg>
</function>
<function e="false">
<var>NewOrder.shipto_stateorprovince</var>
<func>Assign</func>
<arg>var:Entity.address1_stateorprovince</arg>
</function>
<definition e="false">
<var>OpenOrder</var>
<func>Assign</func>
<type>Lookup</type>
<arg>var:NewOrder.@this</arg>
</definition>
<function e="false">
<var>OpenOrder</var>
<func>OpenForm</func>
<arg>String:</arg>
</function>
</action>
</if>
</branch>
</Workflow>
You can fill out the new forms further. In the new order, we set the account's address as the shipping address.
<branch e="false" info="Create a new order button">
<if e="true">
<conditions e="true" op="And">
<condition e="false">
<var>ChangedItem</var>
<op>Equal</op>
<arg>String:Create new order</arg>
</condition>
</conditions>
<action>
<definition e="false">
<var>NewOrder</var>
<func>NewInstance</func>
<type>Entity</type>
<arg>String:salesorder</arg>
</definition>
<function e="false">
<var>NewOrder.customerid</var>
<func>Assign</func>
<arg>var:Entity.@this</arg>
</function>
<function e="false">
<var>NewOrder.createdon</var>
<func>SetToday</func>
</function>
<function e="false">
<var>NewOrder.shipto_country</var>
<func>Assign</func>
<arg>var:Entity.address1_country</arg>
</function>
<function e="false">
<var>NewOrder.shipto_city</var>
<func>Assign</func>
<arg>var:Entity.address1_city</arg>
</function>
<function e="false">
<var>NewOrder.shipto_line1</var>
<func>Assign</func>
<arg>var:Entity.address1_line1</arg>
</function>
<function e="false">
<var>NewOrder.shipto_line2</var>
<func>Assign</func>
<arg>var:Entity.address1_line2</arg>
</function>
<function e="false">
<var>NewOrder.shipto_line3</var>
<func>Assign</func>
<arg>var:Entity.address1_line3</arg>
</function>
<function e="false">
<var>NewOrder.shipto_postalcode</var>
<func>Assign</func>
<arg>var:Entity.address1_postalcode</arg>
</function>
<function e="false">
<var>NewOrder.shipto_stateorprovince</var>
<func>Assign</func>
<arg>var:Entity.address1_stateorprovince</arg>
</function>
<definition e="false">
<var>OpenOrder</var>
<func>Assign</func>
<type>Lookup</type>
<arg>var:NewOrder.@this</arg>
</definition>
<function e="false">
<var>OpenOrder</var>
<func>OpenForm</func>
<arg>String:</arg>
</function>
</action>
</if>
</branch>
In the new appointment, we add the date of creation and name of the appointment by concatenating "Meeting with:" and the account's primary contact.
<branch e="false" info="Create a new appointment button">
<if e="true">
<conditions e="true" op="And">
<condition e="false">
<var>ChangedItem</var>
<op>Equal</op>
<arg>String:Create new appointment</arg>
</condition>
</conditions>
<action>
<definition e="false">
<var>NewAppointment</var>
<func>NewInstance</func>
<type>Entity</type>
<arg>String:appointment</arg>
</definition>
<function e="false">
<var>NewAppointment.regardingobjectid</var>
<func>Assign</func>
<arg>var:Entity.@this</arg>
</function>
<function e="false">
<var>NewAppointment.createdon</var>
<func>SetToday</func>
</function>
<function e="false">
<var>NewAppointment.subject</var>
<func>Concat</func>
<arg>String:Meeting with: </arg>
<arg>var:Entity.primarycontactid</arg>
</function>
<definition e="false">
<var>OpenNewAppointment</var>
<func>Assign</func>
<type>Lookup</type>
<arg>var:NewAppointment.@this</arg>
</definition>
<function e="false">
<var>OpenNewAppointment</var>
<func>OpenForm</func>
<arg>String:</arg>
</function>
</action>
</if>
</branch>
OpenForm with JSON options
Note that the OpenForm operation allows specifying options in JSON format. For example, you can use the following syntax:
{ "@initialize": { "name": "MyOrder", "discountamount": "100" } }
The opened form is not marked as "dirty". You can use the @dirty parameter to override this behavior.

<definition e="false">
<var>var1</var>
<func>LoadFetch</func>
<type>Entity</type>
<arg>String:invoice</arg>
<arg>Fetch:<fetch><entity name='invoice'/></fetch></arg>
</definition>
<function e="false">
<var>var1.@this</var>
<func>OpenForm</func>
<arg>String:{ "@initialize": { "name": "MyOrder", "discountamount": "100" } }</arg>
</function>
You can use OpenForm to launch a questionnaire; however, the JSON options are ignored.
Example: start questionnaire by clicking the button
Clicking the Inspections button opens up a new questionnaire.
If the button is clicked, we fetch questionnaire template which is published and its name equals "Equipment checkup". If this fetch contains data, the questionnaire is opened.
<branch e="false" info="Inspection button">
<if e="true">
<conditions e="true" op="And">
<condition e="false">
<var>ChangedItem</var>
<op>Equal</op>
<arg>String:Start Inspection</arg>
</condition>
</conditions>
<action>
<definition e="false">
<var>var3</var>
<func>LoadFetch</func>
<type>Entity</type>
<arg>String:resco_questionnaire</arg>
<arg>Fetch:<fetch version="1.0"><entity name="resco_questionnaire"><filter type="and"><condition attribute="statuscode" operator="eq" value="473220002" /><condition attribute="resco_istemplate" operator="eq" value="1" /><condition attribute="resco_name" operator="eq" value="Equipment checkup" /></filter></entity></fetch></arg>
</definition>
<branch e="true" info="">
<if e="true">
<conditions e="true" op="And">
<condition e="false">
<var>var3.@this</var>
<op>ContainsData</op>
</condition>
</conditions>
<action>
<function e="false">
<var>var3.@this</var>
<func>OpenForm</func>
<arg>String:</arg>
</function>
</action>
</if>
</branch>
</action>
</if>
</branch>
Used Fetch:
To see the rule execution in the app, click here.
Example: Save and close form
In this example, we execute a simple JavaScript function from rules that saves and closes the current form.
- Add an offline HTML file to your form with the following script (taken straight from our GitHub wiki).
function saveAndCloseForm() { MobileCRM.UI.EntityForm.requestObject(function (entityForm) { /// <param name="entityForm" type="MobileCRM.UI.EntityForm"/> if (entityForm) MobileCRM.UI.EntityForm.saveAndClose(); }, function (err) { MobileCRM.bridge.alert("An error occurred: " + err); }, null); }
- Add a button to your form.

- Add a button click rule. In the example below, "funwithforms" refers to the name of the script file.

<branch e="true" info="Save form and close it by using JS"> <if e="true"> <conditions e="true" op="And"> <condition e="false"> <var>ChangedItem</var> <op>Equal</op> <arg>String:savecloseviaJS</arg> </condition> </conditions> <action> <definition e="false"> <var>var1</var> <func>ExecuteJS</func> <type>String</type> <arg>String:funwithforms</arg> <arg>String:saveAndCloseForm</arg> </definition> </action> </if> </branch>