Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dot Walking with script variables

Florian Ricken
Tera Contributor

Hi together I have a script in which I have a current object which is for example an approval and would like to have the dot walking path built dynamically in the script. For this I already have variables that give me the path as a string and so I thought I could just set this path after the current. Unfortunately this does not work, I get an undefined.
Does anyone have an idea how to solve this cleverly?

if (recipients_fields) {
                for (var k = 0; k < recipients_fields.length; k++) {
                    if (show_button) {
						//Handle dot walked recipients fields
						var user3 = new GlideRecord("sys_user");
						if(recipients_fields[k].indexOf(".")!=-1){
							var split = recipients_fields[k].split('.');
							var dotWalkedPart = split[0].toString();
							var field = split[1].toString();
							if (user3.get("sys_id", current.dotWalkedPart.getValue(field))) {
                            if (user3.getValue("locked_out").toString() == "1")
                                show_button = false;
                        }
						}else{
							if (user3.get("sys_id", current.getValue(recipients_fields[k]))) {
                            if (user3.getValue("locked_out").toString() == "1")
                                show_button = false;
                        }
						}//End handle dot walked fields
						
                        
                        
                    } else
                        break;
                }
            }
3 REPLIES 3

Javier Tirado1
Tera Guru

Hi Florian, did you worked this out?

I have something like:

var variableName = "name";

var field = "current.variables." + variableName;

 

field will return a string -> "current.variables.name" , but I want to achieve the sys_id which would return if I just write the dot-walk normally.

ricker
Tera Guru

@Florian Ricken,

You don't need getValue server side or the field name "sys_id" when using get.

Instead of

if (user3.get("sys_id", current.dotWalkedPart.getValue(field))) {

Try this

if (user3.get(current.field_name)) {//this would be the value of the field...you'll get a sys_id when it's a reference field.

 

}