Scripting to override field values

Open the entry for the priority field map property again and check the Use source script field. As shown in the following screenshot, the Source script field will now be visible:

Use the following code in the Source script field:

answer = (function transformEntry(source) { 
     
  if(source.u_priority.nil()) 
    return "3 - Moderate"; // return the value to be put into the target field 
  else 
    return source.u_priority; // return the value to be put into the target field 
})(source); 

In the preceding code, we have used the source GlideObject object available to us to check the value of the u_priority (priority) field in staging the import set table. We have set 3 - Moderate as the default value if the value of the priority field in the staging table is nil. Thus, whenever a row that has a nil or blank value, the value 3 - Moderate will be inserted into the priority field of the target Booking request table. Click on the Update button to save the Field Map property. In the field maps related list in the transform map detail form, you may notice that the value of the Source field column for the field map entry we just edited, as shown in the following screenshot, has been changed to [Script]:

This is an absolutely normal system behavior because we are now using a script as a source to calculate the value for the target priority field.

We can employ field map level scripting to concatenate values, perform system properties checks, database lookup by creating GlideRecord objects, and so on, to accomplish different project solutions. While field level scripting is good for cases where we want to parse, override, check, or validate field values, we can also specify scripts at the transform map level to control row-level actions, such as insert, update, and skip. Let's write a transform map script that will control how the rows will be inserted programmatically.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.59.231