Table maps can be configured to use scripts to serialize the record yourself. Within the script, you can set the variable answer to be the value you want the record to be serialized and returned as.

The following variables are available to use:

VariableDescription
currentThis represents the record that is being shared
gr_tablemapThis represents the outbound table map itself. For example if you want to access the table map's name, you can use gr_tablemap.u_name

(info) NOTE: Adding a script to your table map is an advance configuration. Contact Perspectium Support for more information. 


Example of a table map script

/*
 * Custom Table Map
 */
 
//Serialize 'current' record into an XMLDocument
var recordSerializer = (typeof GlideRecordXMLSerializer != 'undefined') ? new GlideRecordXMLSerializer() : new Packages.com.glide.script.GlideRecordXMLSerializer(); 
var xmlstr = recordSerializer.serialize(current);
var xmlDoc = new XMLDocument(xmlstr);
 
//Process Display Values As Necessary
var pspUtil = new PerspectiumUtil();
var addDisplayValues = pspUtil.getPspPropertyValue("com.perspectium.replicator.add_display_values", "true");
var currentFieldsOnly = pspUtil.getPspPropertyValue("com.perspectium.replicator.share_current_fields", "false");
if (currentFieldsOnly == "true" || addDisplayValues == "true") {
    addDVFields();
}
 
/*
 * Any extra mapping, to add
 */
 
// Send the XMLDoc string to our answer
answer = xmlDoc.toString();
 
// Helper Functions
 
//Standard DV Field Processing
function addDVFields(){
    var fl = (typeof GlideFieldList != 'undefined') ? new GlideFieldList() : new Packages.com.glide.processors.FieldList();
    var tableName = current.getTableName();
    var fieldNames = fl.get(current.getTableName(),"");
    var arrFields = current.getFields();
 
    for (var i = 0; i < arrFields.size(); i++) {
        var glideElement = arrFields.get(i);
        var ed = glideElement.getED();
        var elName = glideElement.getName();
 
        if (!fieldNames.contains(elName) || (currentFieldsOnly == "true" && tableName != ed.getTableName())) {
            removeElement(elName);
        }
 
        // Create dv fields for reference, choice, or lists
        if (ed.isReference() || ed.isChoiceTable() || ed.getInternalType() == "glide_list") {
            addElement("dv_" + elName, glideElement.getDisplayValue());
        }
 
        if (!glideElement.hasValue()) {
            continue;
        }
    }
}
 
//Remove an element from xmlDoc
function removeElement(elName){
    var nn = xmlDoc.getElementByTagName(elName);
    if(nn && nn.parentNode) {
        nn.parentNode.removeChild(nn);
    }
}
//Add an element from xmlDoc
function addElement(elName, elValue){
    xmlDoc.createElement(elName, elValue);
}

The example above mimics the replication process with some customizations by using a table map. The script will contain the following:

  1. Creating and serializing the base record

  2. Adding Display Values as necessary

  3. A section for your custom changes

  4. Converting the XMLDocument to a string and assigning it to the answer variable

  5. Helper functions which you can call

You can then utilize the function removeElement(elName) and addElement(elName, elValue) to modify the outgoing columns and data as you see fit.


(info) NOTE: To use current.operation() or psp_action, there is an on-goin research on retaining value of current.operation() in the Table Map and Field Map. As a workaround, use current.psp_action = action.

Thus, the following can be added to the dynamic share's Before Share Script to address both concerns:

current.psp_action = psp_action;
var prev = new GlideRecord(current.getTableName());
prev.get('sys_id', current.sys_id);


Procedure

To add a script to your table map, follow these steps: 


Navigate to table map 

Log into your ServiceNow instance and navigate to Perspectium Control and Configuration > Table Maps. Click into the table map that you want to add a script to or create a new table map. 

Enable script

Under the Mapping Script section, check the Use Script box. 

Then, fill the Script field with the desired script. 

Then, click Update to save your changes.