Skip to content

Instantly share code, notes, and snippets.

@jlrjr
Last active November 6, 2015 15:18
Show Gist options
  • Save jlrjr/08b681999ce2532590d9 to your computer and use it in GitHub Desktop.
Save jlrjr/08b681999ce2532590d9 to your computer and use it in GitHub Desktop.
ServiceNow background script to check import transform map choice actions
//change to sysid of app you want to scan
var appID = "e32a61c94f198a004f167d2ca310c72a";
reviewTransformChoiceActionsForApp(appID);
function reviewTransformChoiceActionsForApp(appId) {
var entry = new GlideRecord("sys_transform_entry");
entry.addQuery("sys_scope", appId);
entry.orderBy("map");
entry.query();
while (entry.next()) {
targetTable = entry.getValue("target_table");
targetField = entry.getValue("target_field");
var choiceFieldType = getChoiceFieldType(targetTable, targetField);
if (!choiceFieldType)
continue;
gs.info("{0} - {1}.{2} ({3}), {4}", entry.map.getDisplayValue(), targetTable, targetField, choiceFieldType, entry.getValue("choice_action"));
}
}
function getChoiceFieldType(table, element) {
var gr = new GlideRecord(table);
gr.initialize();
var el = gr.getElement(element);
var internalType = j2js(el.getED().getInternalType());
if (internalType == "reference")
return "reference";
if (internalType == "choice" || (internalType == "string" && j2js(el.getChoices()).length > 0)) {
return "choice";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment