Glide List Script for PA Breakdown Mapping

KBoz
Tera Expert

We have a glide list field on Incidents for tracking the groups involved.  I would like to pick off the first value from that list and use it in a breakdown mapping.  Below is what I have so far, but not sure I am on the right track.  How do I write the script to only bring back the first value in the list?

KBoz_0-1685627059235.png

 

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

You are close, you just need to drop the loop since you just want the first value.

(function(){
	if(current.u_glide_list_1){
		var groups = ("" + current.getValue("u_glide_list_1")).split(",");
		if(groups.length > 0){
			var gr = new GlideRecord("sys_user_group")
			if(gr.get(groups[0])){
				gs.log(gr.getValue("name"));
				return groups[0]; //This will return the sys_id of the group.
			} else {
				return "";
			}
		} else {
			return "";
		}
	} else {
		return "";
	}
})();

View solution in original post

3 REPLIES 3

DrewW
Mega Sage
Mega Sage

You are close, you just need to drop the loop since you just want the first value.

(function(){
	if(current.u_glide_list_1){
		var groups = ("" + current.getValue("u_glide_list_1")).split(",");
		if(groups.length > 0){
			var gr = new GlideRecord("sys_user_group")
			if(gr.get(groups[0])){
				gs.log(gr.getValue("name"));
				return groups[0]; //This will return the sys_id of the group.
			} else {
				return "";
			}
		} else {
			return "";
		}
	} else {
		return "";
	}
})();

Thank you for the quick response!  I tried it out am getting the following error below.  Any ideas?

 

Error during JavaScript evaluation: Not all references of "current" are passed in by "arguments" script: (function(){
if(current.u_glide_list_1){
var groups = ("" + current.getValue("u_glide_list_1")).split(",");
if(groups.length > 0){
var gr = new GlideRecord("sys_user_group");
if(gr.get(groups[0])){
gs.log(gr.getValue("name"));
return groups[0]; //This will return the sys_id of the group.
} else {
return "";
}
} else {
return "";
}
} else {
return "";
}
})();

Nevermind.....got it to work!  Thanks for your help ðŸ˜Š

 

(function(){
if(current.u_glide_list_1){
var g = current.u_glide_list_1;

var groups = g.split(",");

if(groups.length > 0){
var gr = new GlideRecord("sys_user_group");
if(gr.get(groups[0])){
gs.log(gr.getValue("name"));
return groups[0]; //This will return the sys_id of the group.
} else {
return "";
}
} else {
return "";
}
} else {
return "";
}
})();