1

Button Click

From Resco's Wiki
Jump to navigation Jump to search
Rules and examples

button icon 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:

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.

button in the app showcase

First, we click Add button and fill in the name of the button (Click text, Label):

AddButton icon button properties.

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.

Create a new order button and create a new appointment button examples

You can fill out the new forms further. In the new order, we set the account's address as the shipping address.

create a new order button example where we fill more fields

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.

create a new appointment button example where we fill more fields

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.

start inspection button example

Used Fetch:

start inspection button example: fetching the questionnaire

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.

  1. 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);
    }
    
  2. Add a button to your form.
    save and close form via js button example
  3. Add a button click rule. In the example below, "funwithforms" refers to the name of the script file.
    alt=save and close form via js button example 2



Was this information helpful? How can we improve?