PDFsuite Custom Forms Mappings

Add Scripts

addScripts

The Add scripts routine can be called as followed

helper.addScripts(scriptConfiguration)

Where scriptConfiguration is a javascript object of key value pairs. the key is the name of the script. This name is used to select the script when defining a field mapping using the script property. The value is a javascript object with the following two properties.

fromServiceNow (optional)

A function that is used to get the value for a field mapping from ServiceNow.

Type: a function that takes the following parameters

  • gr - The GlideRecord for the field mapping.
  • current - The current GlideRecord.
  • fields - All the field mappings, given by an object of key value pairs where the key is the name of the PDF form field, and the value is the ICustomField for the mapping.

toServiceNow (optional)

A function that is used to set the value for a field mapping to ServiceNow.

Type: a function that takes the following parameters

  • gr - The GlideRecord for the field mapping.
  • value - The value that was set on the PDF form.
  • current - the current GlideRecord.
  • fields - All the field mappings, given by an object of key value pairs where the key is the name of the PDF form field, and the value is the ICustomField for the mapping.

Example

In the following example a script named 'name' is added. The script is configured such that when the value is retrieved from ServiceNow it combines the last_name, first_name, and middle_initial fields into a single string. Then when writing the value back to ServiceNow it splits the string up and sets each field with the appropriate values.


    helper.addScripts({
        'name': {
            fromServiceNow: function (gr, current) {
                return gr.last_name + ', ' + gr.first_name + ', ' + gr.middle_initial;
            },
            toServiceNow: function (gr, value, current) {
                var names = value.split(',');
                if (names.length > 0) {
                    gr.last_name = names[0].trim();
                    if (names.length > 1) {
                        gr.first_name = names[1].trim();
                    }
                    if (names.length > 2) {
                        gr.middle_initial = names[2].trim();
                    }
                }
            }
        }
    })