Jump to content

Mapping questions to fields: Difference between revisions

From Resco's Wiki
Marek Rodak (talk | contribs)
Line 41: Line 41:
== Example: refresh form after completing questionnaires ==
== Example: refresh form after completing questionnaires ==


'''Problem''': Start a questionnaire from an entity form. The questionnaire uses data mapping to modify the record data. After completing the questionnaire, data is changed, but the form is not refreshed automatically, showing old data. User needs to close and reopen the form and that's a not intuitive and redundant step.
'''Problem''': Start a questionnaire from an entity form. The questionnaire uses data mapping to modify the record data. After completing the questionnaire, data is changed, but the form is not refreshed automatically, showing old data. User needs to close and reopen the form and that's an unintuitive and redundant step.


'''Solution''': Use an [[On Change]] rule [[Form#onChange|triggered by a change]] in the Inspections tab to [[Execute JavaScript from rules|execute a JavaScript function]] that refreshes the form.
'''Solution''': Use an [[On Change]] rule [[Form#onChange|triggered by a change]] in the Inspections tab to [[Execute JavaScript from rules|execute a JavaScript function]] that refreshes the form.

Revision as of 09:21, 23 February 2023

The data mapping feature allows you to map a question to a particular record field. You can read a field to populate the answer automatically or save the answer to a record field at the end – or both.

Identify the mapped record

You have several options for indicating which record and field should be mapped to an answer.

  • One of the simplest options is using the regarding record. This is the record from which the questionnaire was started. If your workflow assumes that you launch questionnaires from an entity form, for example, you go to an asset and start the inspection, this is the way to go.
  • If you have a list of questionnaire templates directly on your home screen or start inspection differently, the regarding field is empty. Instead, you can add a lookup question to your questionnaire template and then use the lookup target as the mapped record.

Set the mapping direction

Once you identify the record and field, you can choose mapping direction. Essentially, you can:

  • read data from the record to populate the answer on the questionnaire
  • write data from the answer into the record field
  • or both!

You can read the data only once, when the questionnaire is created, or repeatedly, whenever you open an incomplete questionnaire.

You can save the data only once, when the questionnaire is completed, or repeatedly, whenever you save an in-progress questionnaire.

Edit the questionnaire template

  1. Edit a questionnaire template in the designer and enable Data Mapping in the toolbar.
  2. Click the link button to start the data mapping wizard.
  3. Select which record should be linked to the question:
    • Regarding record (Record from which the questionnaire was started)
    • Record from a lookup question
  4. For each entity, select the record that should be mapped.
  5. Finally, select whether to read data from the record field or save the answer to the field.

Select record Select mapped fields for the regarding record Select mapped fields for the lookup record Select when to apply mapping

Usage in the app

Once you start such a questionnaire in the app, the record data can populate the default answers. And when you complete it, changed answers can be saved to the mapped record. For example, your inspection could include details of the inspected entity. In the example below, you can review and update the contact information of your contact directly from the questionnaire.

When you start the questionnaire without a regarding record or without answering the lookup, you can continue using the questionnaire as usual. The data mapping is ignored: the answer is not populated at the start and is only saved in the questionnaire.

Example: refresh form after completing questionnaires

Problem: Start a questionnaire from an entity form. The questionnaire uses data mapping to modify the record data. After completing the questionnaire, data is changed, but the form is not refreshed automatically, showing old data. User needs to close and reopen the form and that's an unintuitive and redundant step.

Solution: Use an On Change rule triggered by a change in the Inspections tab to execute a JavaScript function that refreshes the form.

Allow the Inspections unrelated list to trigger On Change events

  1. Edit the app project in Woodford.
  2. Select the entity from the Project menu and edit the form.
  3. Select the Inspections tab and click Properties.
  4. Go to the Properties tab, enable Trigger OnChange event.
  5. Save all changes.

Add an iframe and upload JavaScript

  1. On the entity form, click Add IFrame, then click Manage.
  2. Verify that a recent version of JSBridge.js is included in the offline HTML.
  3. Create or import an HTML file with the simple script listed below.
  4. Save and close the Offline HTML window.
  5. On the Configure IFrame window, enter the name of the script file.
  6. Click OK and save all changes.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Empty Offline HTML page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="initial-scale=1, user-scalable=no" />
    <script src="JSBridge.js"></script>
</head>
<body>
    <script>
        function refreshForm(){
        MobileCRM.UI.EntityForm.refreshForm();
        }
        function saveForm() {
            MobileCRM.UI.EntityForm.save();
        }
    </script>
</body>
</html>

This example includes only two simple functions:

  • Use refreshForm if you only need to refresh the form without saving possible unsaved changes.
  • Use saveForm to save the form. This automatically refreshes the form.

Create a rule that executes the script

  1. On the entity form, click On Change.
  2. Enter the following rule:
  3. Save all changes.