- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 07:03 PM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 08:46 PM
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])
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 08:46 PM
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])
}
}