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 in Workflow Editor

ramirch
Tera Contributor

Hello!

 

I am modifying a catalog item which still uses the Workflow Editor. There is a variable that references the Group table. I have added an 'If' Workflow activity to get the 'Parent' value from the Groups record. I tried dot walking but it's not working. This is my script.

 

answer = ifScript();

function ifScript() {
    if (current.variables.group.parent == 'Facilities') {
        return 'yes';
    }
    return 'no';
}

 

Please help!

 

Thank you.

2 REPLIES 2

Udayrathore049
Giga Expert

You need to first get the Group record from the variable reference and then access the parent field. You can use a GlideRecord to query the Group table for the record that corresponds to the group selected in the variable.

Here’s how you can modify your script:

answer = ifScript();

function ifScript() {
var group = new GlideRecord('sys_user_group');
if (group.get(current.variables.group)) {
// Now you can access the 'parent' field from the Group record
if (group.parent.name == 'Facilities') {
return 'yes';
}
}
return 'no';
}

Explanation:

GlideRecord for Group Table: You’re creating a GlideRecord object for the sys_user_group table, which is the Group table in ServiceNow.

Retrieving the Group Record: Using the get() method, you fetch the Group record that corresponds to the value in the group variable.

Accessing Parent Field: After successfully retrieving the Group record, you can dot-walk to the parent field and check if the name of the parent group is 'Facilities'.



If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Uday Rathore
ServiceNow Developer
LinkedIn: https://www.linkedin.com/in/uday-rathore049/

Ankur Bawiskar
Tera Patron
Tera Patron

@ramirch 

if you are comparing name of the group then you should dot walk to name field

answer = ifScript();

function ifScript() {
    if (current.variables.group.parent.name.toString() == 'Facilities') {
        return 'yes';
    }
    return 'no';
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader