Transform map source validation on choice list target field

olufsen
Kilo Sage

I need assistance from the expert on how to implement my additional requirement.

I have a source field location i.e. Japan, India, Iceland, USA, UK and I want to make sure this string records separated by comma to be validated from my customed list field of only 10 sets of location.

If one value of the source string is not found in the list, exclude it in the target field.

 

Source: loc = 'Japan, India, Iceland, USA, UK'

Target: Location (u_location) Data type: List with 10 choice list.

Table: sys_choice; Filter: elementSTARTSWITHu_location

 

In the source, Iceland is NOT a VALID location and should not be created in the target field. Only values of Japan, India, USA, UK will be set.

 

answer = (function transformEntry(source) {

    var answer;
    var loc = source.u_loc.toLowerCase.split(',');
    //var locArr = [];

    var grChoice = new GlideRecord('sys_choice');
    grChoice.addEncodedQuery('elementSTARTSWITHu_location');
    grChoice.addQuery('value', 'CONTAINS', loc);
    grChoice.query();
    if (grChoice.next()) {
        answer = target.u_location = loc;;
    } else {
        //log.warn("No value found for location ");
        ignore = true;
        return target.comments = "No corresponding value found in ServiceNow for " + source.u_loc;
    }
    return answer;

})(source);

 

1 ACCEPTED SOLUTION

olufsen
Kilo Sage
var locSplit = loc.split(';');

for(var i=0; i<locSplit.length; i++){
var grChoice = new GlideRecord('sys_choice');
grChoice.addEncodedQuery('elementSTARTSWITHu_jurisdiction');
grChoice.addQuery('label', 'CONTAINS', locSplit[i]);
grChoice.query();
if(grChoice.next()){
gs.info("Label " + locSplit[i]);
} else {
gs.info("Value not found for " + locSplit[i])
}

}

View solution in original post

1 REPLY 1

olufsen
Kilo Sage
var locSplit = loc.split(';');

for(var i=0; i<locSplit.length; i++){
var grChoice = new GlideRecord('sys_choice');
grChoice.addEncodedQuery('elementSTARTSWITHu_jurisdiction');
grChoice.addQuery('label', 'CONTAINS', locSplit[i]);
grChoice.query();
if(grChoice.next()){
gs.info("Label " + locSplit[i]);
} else {
gs.info("Value not found for " + locSplit[i])
}

}