Jump to content

On Load: Difference between revisions

From Resco's Wiki
Marek Rodak (talk | contribs)
Marek Rodak (talk | contribs)
No edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Rules TOC}}
{{Rules TOC}}
<span style="float:left; padding-right:10px">[[File:On Load icon.PNG|100 px]]</span>
<span style="float:left; padding-right:10px">[[File:On Load icon.PNG|alt=On Load icon|100 px]]</span>
Rules are client-side scripts (no-code [[business logic]]) that are executed when a user of the mobile app interacts with the app.  
Rules are client-side scripts (no-code [[business logic]]) that are executed when a user of the mobile app interacts with the app.  
The '''On Load rules''' are executed when you open a form or a questionnaire. Rules are managed using the [[rules editor]], usually in [[Woodford]].  
The '''On Load rules''' are executed when you open a form or a questionnaire. Rules are managed using the [[rules editor]], usually in [[Woodford]].  
Line 39: Line 39:
If the field Don’t Allow Emails is set to "Do Not Allow", make Email field not visible on the form.
If the field Don’t Allow Emails is set to "Do Not Allow", make Email field not visible on the form.


[[File:Hide email field.png|600px]]
[[File:Hide email field.png|alt=On Load: Hide email field rule example|600px]]


=== Example: Change style on form ===
=== Example: Change style on form ===
Line 45: Line 45:
If the Rating belongs to category "Hot", assign "HotLead" style, otherwise set "Normal" style.  
If the Rating belongs to category "Hot", assign "HotLead" style, otherwise set "Normal" style.  


[[File:Assign style.png|600px]]
[[File:Assign style.png|alt=On Load: Change style on form rule example|600px]]


===Example: Empty fields are filled with placeholder===
===Example: Empty fields are filled with placeholder===
Line 51: Line 51:
If the street field is empty, fill each field for the address with the corresponding placeholder.  
If the street field is empty, fill each field for the address with the corresponding placeholder.  


[[File:Placeholders.PNG|600px]]
[[File:Placeholders.PNG|alt=On Load: Empty fields are filled with placeholder rule example|600px]]


===Example: Assign systemuser as owner===
===Example: Assign systemuser as owner===
Line 57: Line 57:
If the Owner and Created on fields are empty, assign systemuser as owner of the record.
If the Owner and Created on fields are empty, assign systemuser as owner of the record.


[[File:Assign systemuser.PNG|600px]]
[[File:Assign systemuser.PNG|alt=On Load: Assign systemuser as owner rule example|600px]]
 
===Example: Assing currency from entity user===
 
If the entity isNew equals true, create variable user, where we load reference from entity user.Owner --> systemuser. Clear the currency field and assign the value transactioncurrency field from the variable user.
 
[[File:Assing currency from entity user.PNG|alt=On Load: Assing currency from entity user rule example|600px]]


===Example: Count the number of associated contacts (for account)===
===Example: Count the number of associated contacts (for account)===
Line 63: Line 69:
We create shared variable "contactCount" (integer). Then we create the variable "count"(integer), where we load all contacts related to the account through the Customer lookup field and count them. If variable "count" contains data, its assigned to shared variable "contactCount". The shared variable can then be placed on desired form list.
We create shared variable "contactCount" (integer). Then we create the variable "count"(integer), where we load all contacts related to the account through the Customer lookup field and count them. If variable "count" contains data, its assigned to shared variable "contactCount". The shared variable can then be placed on desired form list.


[[File:ContactCount.png|600px]]
[[File:ContactCount.png|alt=On Load: Count the number of associated contacts (for account) rule example|600px]]


Used Fetch:
Used Fetch:


[[File:Contactcountfetch.PNG|600px]]
[[File:Contactcountfetch.PNG|alt=On Load: Count the number of associated contacts (for account) rule example (used fetch)|600px]]


===Example: Expand Contact Tab (on account), if associated contacts found===
===Example: Expand Contact Tab (on account), if associated contacts found===
Line 73: Line 79:
We create a variable where we fetch all contacts associated to the customer (Account). If this variable contains data (records found), Contact tab on the form is expanded. Else if the variable is empty (no records found), the Contact tab is not expanded.
We create a variable where we fetch all contacts associated to the customer (Account). If this variable contains data (records found), Contact tab on the form is expanded. Else if the variable is empty (no records found), the Contact tab is not expanded.


[[File:Customercontatcs.PNG|600px]]
[[File:Customercontatcs.PNG|alt=On Load: Expand Contact Tab (on account), if associated contacts found rule example|600px]]


Used Fetch:
Used Fetch:


[[File:Customercontatcs fetch.PNG|600px]]
[[File:Customercontatcs fetch.PNG|alt=On Load: Expand Contact Tab (on account), if associated contacts found rule example (used fetch)|600px]]


=== Example: Create a Task on the form through an unrelated entity list on event entity ===
To see the rule execution in the app, click [https://youtu.be/ToK2Rz0q-gc here].
In this rule, we want to create a Task from the event entity (Order in this case) and automatically fill in the regarding field with the customer id.  


First, we add an unrelated Task list to the Order form.
=== Example: Populate fields of the new Task record created on the list of another entity (Relationship.target)===
In this example, we want to create a Task through the task list on the Order form and automatically fill in the regarding field with the customer id.  


[[File:Tasklist.PNG]]
First, we add the Task list to the Order form.


We have to edit the Task list filter to see only tasks regarding current Order customer.
[[File:Tasklist.PNG|alt=On Load: Populate fields of the new Task record created on the list of another entity (Relationship.target) rule example part 1 (add Task to Order entity)]]
Used Filter:


[[File:Order unrelatedtasktab filter.PNG|600px]]
If the Task is new and relationship.target (where was the task creation initiated), type salesorder, load reference from this relationship.target -> Salesorder into a variable, and assign it to the Regarding field.


If the Task is new and relationship.target (where was the task creation initiated), type salesorder, load reference from this relationship.target -> Salesorder into a variable, and assign it to the Regarding field.
[[File:TaskOnLoad relationshiptarget.PNG|alt=On Load: Populate fields of the new Task record created on the list of another entity (Relationship.target) rule example part 2 (rule)|600px]]


[[File:TaskOnLoad relationshiptarget.PNG|600px]]
To see the rule execution in the app, click [https://www.youtube.com/watch?v=ZadjUM83wLY here].


== Questionnaires ==
== Questionnaires ==
Line 108: Line 113:
When a user starts new questionnaire, some of the questions are automatically filed in.  
When a user starts new questionnaire, some of the questions are automatically filed in.  


[[File:Rules example.png|600px]]
[[File:Rules example.png|alt=On Load: Automatically filled fields in questionnaire rule example|600px]]


=== Example: Measure the duration of inspection ===
=== Example: Measure the duration of inspection ===
Line 118: Line 123:
We create a shared variable, StartInspection, where we assign the current time (by SetNow). We then assign this value to the start-of-inspection question.
We create a shared variable, StartInspection, where we assign the current time (by SetNow). We then assign this value to the start-of-inspection question.


[[File:Inspection start time.PNG|600px]]
[[File:Inspection start time.PNG|alt=On Load: Measure the duration of inspection rule example (On Load part)|600px]]


;On Save part:
;On Save part:
Line 124: Line 129:
We create a shared variable EndInspection, where we assign the current time (by SetNow). We then assign this value to the end-of-inspection question. We then create a variable var2 where we calculate the timedifference between StartInspection and EndInspection (the result is set to be in minutes). In the end, we assign var2 to question inspection.time.
We create a shared variable EndInspection, where we assign the current time (by SetNow). We then assign this value to the end-of-inspection question. We then create a variable var2 where we calculate the timedifference between StartInspection and EndInspection (the result is set to be in minutes). In the end, we assign var2 to question inspection.time.


[[File:Inspection end time.PNG|600px]]
[[File:Inspection end time.PNG|alt=On Load: Measure the duration of inspection rule example (On Save part)|600px]]


{{Note|Questions start-of-inspection and end-of-inspection are optional. They are not required for the rule to work.}}
{{Note|Questions start-of-inspection and end-of-inspection are optional. They are not required for the rule to work.}}
Line 132: Line 137:
Regarding lookup is a special component. When you open the questionnaire from an entity record, it is automatically filled with the record id. This way, we can set up a rule that automatically fills in questions from the regarding lookup entity (Appointment in this case).
Regarding lookup is a special component. When you open the questionnaire from an entity record, it is automatically filled with the record id. This way, we can set up a rule that automatically fills in questions from the regarding lookup entity (Appointment in this case).


[[File:Regardinglookupcomponent appointment.PNG|600px]]
[[File:Regardinglookupcomponent appointment.PNG|alt=On Load: Populate the questions with data from regarding lookup entity rule example part 1 (regarding lookup question type)|600px]]


We create a shared variable, where we want to store the appointment record. If question.resco_regardingid.value (regarding lookup) contains data and is of type appointment (comes from appointment), assign its value to appointmentRecord. If the appointmentRecord contains data, we can fill the data into the questions.
We create a shared variable, where we want to store the appointment record. If the question.resco_regardingid.value (regarding lookup) contains data and is of type appointment (comes from appointment), assign its value to appointmentRecord. If the appointmentRecord contains data, we can fill the data into the questions.


[[File:Regarding object lookup.PNG|600px]]
[[File:Regarding object lookup.PNG|alt=On Load: Populate the questions with data from regarding lookup entity rule example part 2 (rule - regarding entity(appointment))|600px]]


Optionally, you can access data from an appointment regarding entity (Account in this case). Instead of filling questions with appointment record fields, create a string variable where we load the appointment id. In the following variable we fetch an account regarding appointment, where the id is equal. If the variable (regarding account) contains data, we can fill in the questions with data inside.
To see the rule execution in the app, click [https://www.youtube.com/watch?v=emTJULky_mo here].


[[File:Regardingobjectlookup Account.PNG|600px]]
Optionally, instead of filling questions with appointment record fields, we can go even further and use regarding entity of Appointment. Create a string variable where we load the appointment id. In the following variable we fetch an account regarding appointment, where the id is equal. If the variable (regarding account) contains data, we can fill in the questions with data inside.
 
[[File:Regardingobjectlookup Account.PNG|alt=On Load: Populate the questions with data from regarding lookup entity rule example part 2 (rule alternative - regarding entity of appointment)|600px]]


Used Fetch:
Used Fetch:


[[File:Regardingobjectlookup AccountFetch.PNG|600px]]
[[File:Regardingobjectlookup AccountFetch.PNG|alt=On Load: Populate the questions with data from regarding lookup entity rule example part 3 (used fetch)|600px]]


=== Example: Populate the questions with data from regarding lookup entity 2===
=== Example: Populate the questions with data from regarding lookup entity 2===
Line 150: Line 157:
Similarly, as in previous example, we want to populate question with regarding lookup entity data. In this example, we want to populate root questions and two question groups in the questionnaire. This means we have to specify On Load rules for each question group.  For the following rules we use three shared variables:
Similarly, as in previous example, we want to populate question with regarding lookup entity data. In this example, we want to populate root questions and two question groups in the questionnaire. This means we have to specify On Load rules for each question group.  For the following rules we use three shared variables:


[[File:Shared variables for loading data to questionnaire.PNG|600px]]
[[File:Shared variables for loading data to questionnaire.PNG|alt=On Load: Populate the questions with data from regarding lookup entity 2 rule example part 1 (create shared variables)|600px]]


We start with root questions where we want to load data from regarding lookup entity (workorder/workorderschedule).  
We start with root questions where we want to load data from regarding lookup entity (workorder/workorderschedule).  


[[File:Regardinglookupcomponent workorder.PNG|600px]]
[[File:Regardinglookupcomponent workorder.PNG|alt=On Load: Populate the questions with data from regarding lookup entity 2 rule example part 2 (regarding entity question type)|600px]]


'''Root questions''': If regardingid.value (lookup) contains data and is type of workorderschedule, we create a variable where we loadreference from workorderschedule. If this variable contains data, we assign workorderid to shared variable OriginalWO and work-order-number. Else if regarding.value contains data and is type of workorder, we can assign it directly to OriginalWO and work-order-number.
'''Root questions''': If regardingid.value (lookup) contains data and is type of workorderschedule, we create a variable where we loadreference from workorderschedule. If this variable contains data, we assign workorderid to shared variable OriginalWO and work-order-number. Else if regarding.value contains data and is type of workorder, we can assign it directly to OriginalWO and work-order-number.


[[File:Load workorder data.PNG|600px]]
[[File:Load workorder data.PNG|alt=On Load: Populate the questions with data from regarding lookup entity 3 rule example (root question group rule)|600px]]


'''Customer question group''': If the root question work-order-number and shared variable OriginalWO contains data, we assign OriginalWO.customerid to customer.name question and shared variable Customer. From then on, we fill the customer information questions from shared variable Customer (primary contact, address...).  
'''Customer question group''': If the root question work-order-number and shared variable OriginalWO contains data, we assign OriginalWO.customerid to customer.name question and shared variable Customer. From then on, we fill the customer information questions from shared variable Customer (primary contact, address...).  


[[File:Load customer data.PNG|600px]]
[[File:Load customer data.PNG|alt=On Load: Populate the questions with data from regarding lookup entity 4 rule example (customer group rule)|600px]]


'''Equipment question group''': Same as in previous question group, we assign assetid from OriginalWO to equipment and shared variable Asset. From shared variable Asset we then fill the rest of equipment questions.
'''Equipment question group''': Same as in previous question group, we assign assetid from OriginalWO to equipment and shared variable Asset. From shared variable Asset we then fill the rest of equipment questions.


[[File:Load asset data.PNG|600px]]
[[File:Load asset data.PNG|alt=On Load: Populate the questions with data from regarding lookup entity 5 rule example (equipment question group rule)|600px]]
 
To see the rule execution in the app, click [https://www.youtube.com/watch?v=Cr0USdRXINE here].
 
{{Note|In addition, if initiation of the questionnaire is only possible through workorderschedule or workorder (or any entity), we can disable questions (set them as not editable) that are automatically populated from them (like work-order-number, customer name). }}
 
 
 
 
 


{{Note|In addition, if the access to the questionnaire is only possible through workorderschedule or workorder, we can disable fields that are filled automatically and should not change (like work-order-number, customer name).}}
{{Feedback}}

Latest revision as of 12:54, 20 November 2023

On Load 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 On Load rules are executed when you open a form or a questionnaire. Rules are managed using the rules editor, usually in Woodford.
On Load rules are available for the following user interface components:

Use On Load for initialization

On Load rules are designed and should be used for various steps handling the initialization of components or form styles. The reason for this is simple – users must wait for the On Load rule to be fully executed before they are able to see the form in the desired format. By setting up only the initialization actions in the On Load rule, its execution time is minimal (unless you are handling a great number of conditions and steps in the rule).

These are the recommended steps in On Load rules:

  • Hide/show fields
  • Enable/disable fields
  • Hide/show form tabs
  • Assign styles to fields or to the entire form
  • Automatically assign values to fields, e.g. date & time, location, company number, etc.

Do not set up hide/show/enable/disable fields and tabs dynamically. The actions related to changes on a form while working with it are better set up in the On Change rule.

Forms

Form is a screen in the application that contains numerous fields that either hold or await the data. The default behavior of an entity form can be changed using form rules. Form rules describe sequences of steps that are executed on form-related events. On Load usually serves for handling initialization.

On Load execution
  • Executed right before the form is displayed on the screen. It occurs immediately after the user chooses to open an entity record from the List view screen.

Caching forms

Form caching is a practice that reuses forms. When opening a different record, only the data is replaced; tabs that were collapsed stay collapsed, fields that were hidden remain hidden, etc. Problems may occur if you're using (poorly written) business logic that relies on the form being in the initial default state.

Warning Always remember to add "otherwise if" condition at the end of the rule, to reset the form to default state.

Example: Hide email field

If the field Don’t Allow Emails is set to "Do Not Allow", make Email field not visible on the form.

On Load: Hide email field rule example

Example: Change style on form

If the Rating belongs to category "Hot", assign "HotLead" style, otherwise set "Normal" style.

On Load: Change style on form rule example

Example: Empty fields are filled with placeholder

If the street field is empty, fill each field for the address with the corresponding placeholder.

On Load: Empty fields are filled with placeholder rule example

Example: Assign systemuser as owner

If the Owner and Created on fields are empty, assign systemuser as owner of the record.

On Load: Assign systemuser as owner rule example

Example: Assing currency from entity user

If the entity isNew equals true, create variable user, where we load reference from entity user.Owner --> systemuser. Clear the currency field and assign the value transactioncurrency field from the variable user.

On Load: Assing currency from entity user rule example

Example: Count the number of associated contacts (for account)

We create shared variable "contactCount" (integer). Then we create the variable "count"(integer), where we load all contacts related to the account through the Customer lookup field and count them. If variable "count" contains data, its assigned to shared variable "contactCount". The shared variable can then be placed on desired form list.

On Load: Count the number of associated contacts (for account) rule example

Used Fetch:

On Load: Count the number of associated contacts (for account) rule example (used fetch)

Example: Expand Contact Tab (on account), if associated contacts found

We create a variable where we fetch all contacts associated to the customer (Account). If this variable contains data (records found), Contact tab on the form is expanded. Else if the variable is empty (no records found), the Contact tab is not expanded.

On Load: Expand Contact Tab (on account), if associated contacts found rule example

Used Fetch:

On Load: Expand Contact Tab (on account), if associated contacts found rule example (used fetch)

To see the rule execution in the app, click here.

Example: Populate fields of the new Task record created on the list of another entity (Relationship.target)

In this example, we want to create a Task through the task list on the Order form and automatically fill in the regarding field with the customer id.

First, we add the Task list to the Order form.

On Load: Populate fields of the new Task record created on the list of another entity (Relationship.target) rule example part 1 (add Task to Order entity)

If the Task is new and relationship.target (where was the task creation initiated), type salesorder, load reference from this relationship.target -> Salesorder into a variable, and assign it to the Regarding field.

On Load: Populate fields of the new Task record created on the list of another entity (Relationship.target) rule example part 2 (rule)

To see the rule execution in the app, click here.

Questionnaires

On Load rules in questionnaires are often used to automatically fill in certain fields, for example, the name of the inspector or the inspection date.

Rule execution
  • When when you open a questionnaire.
  • When a repeatable group is repeated.

Example: Automatically filled fields

When a user starts new questionnaire, some of the questions are automatically filed in.

On Load: Automatically filled fields in questionnaire rule example

Example: Measure the duration of inspection

This rule measures the time duration of the inspection. Since the rule has to contain the start and end of the inspection, we need to include both On Load and On Save.

On Load part

We create a shared variable, StartInspection, where we assign the current time (by SetNow). We then assign this value to the start-of-inspection question.

On Load: Measure the duration of inspection rule example (On Load part)

On Save part

We create a shared variable EndInspection, where we assign the current time (by SetNow). We then assign this value to the end-of-inspection question. We then create a variable var2 where we calculate the timedifference between StartInspection and EndInspection (the result is set to be in minutes). In the end, we assign var2 to question inspection.time.

On Load: Measure the duration of inspection rule example (On Save part)

Note Questions start-of-inspection and end-of-inspection are optional. They are not required for the rule to work.

Example: Populate the questions with data from regarding lookup entity

Regarding lookup is a special component. When you open the questionnaire from an entity record, it is automatically filled with the record id. This way, we can set up a rule that automatically fills in questions from the regarding lookup entity (Appointment in this case).

On Load: Populate the questions with data from regarding lookup entity rule example part 1 (regarding lookup question type)

We create a shared variable, where we want to store the appointment record. If the question.resco_regardingid.value (regarding lookup) contains data and is of type appointment (comes from appointment), assign its value to appointmentRecord. If the appointmentRecord contains data, we can fill the data into the questions.

On Load: Populate the questions with data from regarding lookup entity rule example part 2 (rule - regarding entity(appointment))

To see the rule execution in the app, click here.

Optionally, instead of filling questions with appointment record fields, we can go even further and use regarding entity of Appointment. Create a string variable where we load the appointment id. In the following variable we fetch an account regarding appointment, where the id is equal. If the variable (regarding account) contains data, we can fill in the questions with data inside.

On Load: Populate the questions with data from regarding lookup entity rule example part 2 (rule alternative - regarding entity of appointment)

Used Fetch:

On Load: Populate the questions with data from regarding lookup entity rule example part 3 (used fetch)

Example: Populate the questions with data from regarding lookup entity 2

Similarly, as in previous example, we want to populate question with regarding lookup entity data. In this example, we want to populate root questions and two question groups in the questionnaire. This means we have to specify On Load rules for each question group. For the following rules we use three shared variables:

On Load: Populate the questions with data from regarding lookup entity 2 rule example part 1 (create shared variables)

We start with root questions where we want to load data from regarding lookup entity (workorder/workorderschedule).

On Load: Populate the questions with data from regarding lookup entity 2 rule example part 2 (regarding entity question type)

Root questions: If regardingid.value (lookup) contains data and is type of workorderschedule, we create a variable where we loadreference from workorderschedule. If this variable contains data, we assign workorderid to shared variable OriginalWO and work-order-number. Else if regarding.value contains data and is type of workorder, we can assign it directly to OriginalWO and work-order-number.

On Load: Populate the questions with data from regarding lookup entity 3 rule example (root question group rule)

Customer question group: If the root question work-order-number and shared variable OriginalWO contains data, we assign OriginalWO.customerid to customer.name question and shared variable Customer. From then on, we fill the customer information questions from shared variable Customer (primary contact, address...).

On Load: Populate the questions with data from regarding lookup entity 4 rule example (customer group rule)

Equipment question group: Same as in previous question group, we assign assetid from OriginalWO to equipment and shared variable Asset. From shared variable Asset we then fill the rest of equipment questions.

On Load: Populate the questions with data from regarding lookup entity 5 rule example (equipment question group rule)

To see the rule execution in the app, click here.

Note In addition, if initiation of the questionnaire is only possible through workorderschedule or workorder (or any entity), we can disable questions (set them as not editable) that are automatically populated from them (like work-order-number, customer name).




{{#CI form: title = Was this information helpful? How can we improve? | type = inputs | [textarea] }}