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.
A function that is used to get the value for a field mapping from ServiceNow.
Type: a function that takes the following parameters
A function that is used to set the value for a field mapping to ServiceNow.
Type: a function that takes the following parameters
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();
}
}
}
}
})