In this example we’ll take a look at a situation when you don’t want the Resco Mobile CRM app to save changes the user makes to a record, unless there is other particular data associated with it.
When can this be useful?
Your sales reps are following up with a client on a deal, and they need to get in touch with a specific contact from the customer company.
Or, they can save changes to Opportunities only after they have associated products from your portfolio with it.
How can it be achieved?
It is possible to utilize Form Rules to load not only parent record’s data on a child, but also child record’s data, or data from any – even unrelated – entity to a chosen form.
Let’s say we want to make sure that each Account has at least one Contact associated, after this Account has been edited. This can be enabled via the Woodford configuration tool, using the On Save rule on the Account entity.
We will utilize the rule’s Variable section, where not only entity reference via lookup field can be used, but you can also define fetch, that will be used to load data. This is how the rule will look like:
We will create a Variable, where we will load the associated contact record. If the Variable will have a record loaded, it means that at least one contact is associated to the account. This will be specified in the FetchXML. If there is no such contact, the app will display an error message and stop the save of changes made to the Account.
When defining a Variable, first set the type to Entity and enter its name (in our case Contactchild). Then change the Variable’s function to Load Fetch, set target to contact, and click on the three dots next to the empty field to open the filter window, where the actual FetchXML filter is specified:
Now we will create a filter, which will compare the Parent Customer field on Contact with Account’s account ID field using variable. It is a similar approach as in the filtered lookup, in examples, where we filtered contacts using the parent Customer field according to the account ID on an Account.
This is the resulting filter:
Then we just need to specify the condition and the error message step.
The first condition checks if the Variable has at least one record loaded. The “@this” is a pointer to the contact record, so if it does not exist, there is no contact associated. You can use any Contactchild’s field that is required for Contact, e.g. contact’s name.
The second condition is to make sure the rule is not triggered when a new Account record is created, as there cannot be any contact associated until the Account is created, only then you can add associated records.
If the fetch returns more than one record, the first one, that is loaded will be used. The default order is created based on record IDs, ascending. If you want to use a different order, you can export the FetchXML, edit it and import back. This can be done on the FetchXML filter, using the Export/Import command.
Discover more at resco.next 2016
Want to expand your knowledge of Resco and its Woodford configuration tool even further? Join us at Resco Next or enroll in Resco Academy courses.