Sometimes just being able to interact with your Dynamics data in the field isn’t enough, there are times when we need to be smarter to get the most out of the user experience. For those occasions there are Form Rules…
Everyone who’s anyone using a mobility solution for Dynamics CRM seems to be turning to Resco Mobile CRM as their weapon of choice. It is easy to see why, especially if you require a ‘configuration over development’ focused solution. One of the key factors with using Resco is the requirement to configure additional mobile forms for your entities outside of the Dynamics application.
In the Dynamics UI it is possible to use business rules out of the box to determine dynamic field behaviour such as;
- Hide/show fields
- Set the requirement level of a field
- Set the value of a field
There is a full “Rules Guide” available for download via the Resco website which provides a short tutorial and a table of the Function Types that can be called in a rule; click here
Why Use Form Rules?
Form Rules (or Mobile Workflows) in Resco Mobile CRM allow for the standardisation of form and field behaviours, validation and the use of variables based on user input. The best part is that there is no need for programming (just like business rules in Dynamics CRM).
The feature was first implemented in 2012, so is quite mature and offers additional capability to the customisation of Resco Mobile CRM for your users.
When Do I Use Form Rules?
The answer is; whenever you need to modify or validate your forms or fields based on user input in the Resco Mobile CRM app. The rules can be triggered On Load, On Save and On Change as per the Form/Field Events in Dynamics CRM.
How Do I Use Form Rules?
Simple, once you have an established Mobile Project then you can open one of your entity forms and the Rule Editor is launched on click of either the On Lead, On Change or On Save buttons in the ribbon menu.
- On Load – means the rule is executed when the Edit Form is opened
- On Change – means the rule is executed on opening of the Edit Form and also every time a value of one of the form fields changes
- On Save – means the rule is executed when the Save button is selected
Each rule can have conditions, function steps and variables which together provide the logic required to execute the validation or behaviour change you require.
Rules have assigned variables which uses a property to define the scope for the rule to be executed, such as; Entity, Form, Tabs (Views) etc. I have included an example of a simple rule below to illustrate how each component is used, in the example we will throw an error message when there is no data recorded for “Email”.
PLEASE NOTE: This example uses a rule triggered On Change, similar rules can be triggered On Load, but as I want the user to add a value and then the behaviour of the form to change, this is the better option.
- So, to get started – open the Woodford tool and open your project, if needed; see my previous posts on setting up a new project in Woodford here. Then navigate to the account edit form.
- In the Account edit form click “On Change” to add a rule.
3. Click “Add Condition” in the rules editor ribbon menu.
A condition allows for us to include “If” statements in order to execute the rule, for example; “IF Entity.IsNew Equals True” – this condition would mean the rule function only applies to new records. Likewise we can create a condition that looks for a field value such as “Email”; ‘If Entity.emailaddress1 Does Not Contain Data”.+
+Addendum 25/4/17 – If you want to limit when the rule is triggered to the load of the form and where the change field is updated you can add a condition at the beginning of your rule; if ChangedItem Equals <fieldname> – this will have a performance benefit as per the comments from Lukas below. So in this example; if ChangedItem Equals emailaddress1. (Thanks Lukas!)
Conditional strings are added using the pop-out Condition Editor.
After we have defined a condition, we can also add a conditional branch or “Otherwise” statement in the rules editor. You not need to have a condition if the rule will apply to all records in all circumstances.
4. Click “Add Step” in the rule editor ribbon menu
Each functional step allows us to add a variable which requires us to select a “property”, then an “attribute” and a “function”. We can only add a function when the variable has been set.
An example of this could be; “Form.emailaddress1.ErrorMessage” – where Form is the property, emailaddress1 is the attribute and ErrorMessage is the function.
We would then set the action, such as; “Assign” or “Clear” or “Add Suffix” to the function. In this case I am going to use assign – and add a string to display as an error message. So, my complete function is; Form.emailaddress1.ErrorMessage Assign “Email Address is Required” (as per the screen shot below).
There is currently no way of setting a the requirement level of a field outside of CRM, so the above example is useful when you want to have the users add data via Resco that isn’t always ‘required’ in CRM.
PLEASE NOTE: If you want to modify a value of a field on your form you will need to use the “Entity” property in you rule. “Form” properties can be used for hide/show, disable/enable or set an error message for the field selected.
6. To round off the rule I have added a conditional branch as per the image below
Once you have validated your rule using the “Syntax Check” option in the toolbar, save and close the rule and then publish the changes to your project. Then load and sync your device app, the result should be similar to that in the image below. Note that the “Email” field is red, this means the form with expect a value for nay new record added via Resco, if a user attempts to save the record the Resco app throws our error message.
One very useful part of the Form Rule toolkit is the ability to add variables. You can define a variable that is added to the “property selector” in the current rule. This is particularly useful when looking to use more complex conditions or data from a related entity in your rule definition.
Once created, we can call variables in our rule when we are adding conditions and steps.
In this example I will create a variable used on the Email form (edit form) in Resco to pull in the Primary Contact (primarycontactid) value from the regarding account into the description for my greeting. I will use the Concat function to create a text string in the email body;
Step 1 – Open the Email edit form in Woodford and click the “On Change” button in the ribbon
Step 2 – Select “Add Variable” in the rules editor ribbon menu, then define your variable; in this case the property is “Entity”
Step 3 – give your variable a name, here I have used; “RelatedAccount”
Step 4 – In the next option set, select; “Load Reference” (as we are looking to find data on an associated record) and then choose “account” form the list of associated entities and then click “Ok”. The variable is ready to use.
PLEASE NOTE: The related entities in this list also need to be sync’d with Resco for selection.
Step 5 – Select “Add a Condition” then; select your variable from the list and the field, in this case “primarycontactid” then select “Contains Data”
Step 6 – Add a new Step; Entity.description Concat (this gives two arguments)
Step 7 – Add the salutation to the first text area (in this example “Dear”), then in the second click the side button to “choose variable” and then; RelatedAccount.primarycontactid
The resulting variable and rule steps should look like this;
Step 8 – Save and Close then Publish your changes to your project.
Synchronise the Resco app on your device and then navigate to accounts and open a record with a primary contact associated. Open the create email dialog in the activities list, the concatenated values from our rule will be added to the email body.
The same principle applies to adding name strings or text in other fields, Concat3 allows you to use another value or variable when creating a string. You can also use; Add Suffix and Add Prefix to add to an existing text string.
This is a brief intro to the art of the possible with Resco Form Rules, but this post just scratches the surface. If you don’t have access to Resco and Woodford you can download a full trial from Resco.net
Thanks to Jo for the prompt on this post – hope it is useful to some of you and happy mobile CRM’ing! 🙂