How to get the dot walking field value on workflow?

Santhosh15
Tera Guru

Hello All,

 

When i try to dot-walk one custom (list collector) field, which is created on change request.

I try to dot-walk that field it is not working. The field is list collector which is referencing cmdb_ci_appl table. 

I want to fetch the assignment group by dot working, but it is not working.

 

Requirement: Given that one or more Impacted CIs are selected, then approval is requested from the SDM and Manager of the Support group of the Impacted Services / CI(s). Approval is only required from either the SDM or Manager of the group (first to approve). This approval should happen in the ASSESS state.

 

Below code is script include:

==============

 

  getApprovers: function(chgGR) {
        var approvers = [];
        var addlApprovers = [];
 
        var ag = '';
        var agGR = new GlideRecord('change_request');
        agGR.addQuery('sys_id', chgGR);
        agGR.query();
        if (agGR.next()) {
            gs.log("Testing for change" + agGR.number);
            ag = agGR.u_critical_impacted_services_cis.support_group.getRefRecord();
gs.log("Testing for cI" + ag.name);
           // addApprovers(ag);
            if (!hasAlreadyApprovedLastApproval(agGR.u_critical_impacted_services_cis.support_group.manager.getRefRecord(), agGR)) { //1) If AG Mgr has not already approved
                approvers.push(agGR.u_critical_impacted_services_cis.support_group.manager.getRefRecord());
                gs.log("Testing for manager approver" + agGR.u_critical_impacted_services_cis.support_group.manager.getRefRecord());
                if (!gs.nil(agGR.u_critical_impacted_services_cis.support_group.u_sdm.getRefRecord()))
                    approvers.push(agGR.u_critical_impacted_services_cis.support_group.u_sdm.getRefRecord());
            } else if (!gs.nil(agGR.u_critical_impacted_services_cis.support_group.u_sdm.getRefRecord())) { //2) If AG Mgr already approved and had SDM, send to both
                approvers.push(agGR.u_critical_impacted_services_cis.support_group.manager.getRefRecord());
                approvers.push(agGR.u_critical_impacted_services_cis.support_group.u_sdm.getRefRecord());
            } //2.1) Do not send any additional approvals if AG Mgr has already approved and no SDM
        }
 
 
        // if(!gs.nil(chgGR.u_additional_assignment_groups)){
        // addlApprovers = chgGR.u_additional_assignment_groups.split(',');
        // addlApprovers.forEach(addAdditionalApprovers,approvers);
        // }
 
        // return approvers;
    },
    addApprovers: function(agGR) {
        if (!hasAlreadyApprovedLastApproval(agGR.manager)) { //1) If AG Mgr has not already approved
            approvers.push(agGR.manager);
            gs.log("Testing for manager approver" + agGR.manager);
            if (!gs.nil(agGR.u_sdm))
                approvers.push(agGR.u_sdm);
        } else if (!gs.nil(agGR.u_sdm)) { //2) If AG Mgr already approved and had SDM, send to both
            approvers.push(agGR.manager);
            approvers.push(agGR.u_sdm);
        } //2.1) Do not send any additional approvals if AG Mgr has already approved and no SDM
    },
 
    //for each additional assignment group, need to lookup the SDM person assigned to group
    addAdditionalApprovers: function(item) {
        var grp = new GlideRecord("sys_user_group");
        if (grp.get(item)) {
            addApprovers(grp);
        }
    },
 
    //has the user specified already made an approval on the current record
    hasAlreadyApprovedLastApproval: function(userSysId, chgGR1) {
        if (gs.nil(userSysId))
            return true;
 
        var grApproval = new GlideRecord('sysapproval_approver');
        grApproval.addQuery('document_id', chgGR1);
        grApproval.addQuery('approver', userSysId);
        grApproval.orderByDesc('sys_created_on');
        grApproval.query();
 
        return grApproval.next() && grApproval.getValue('state') === 'approved';
    },
 
    isApproved: function(chgGR) {
 
        return "";
    },




Thank you all in advance

@Maik Skoddow @Ankur Bawiskar @Samaksh Wani @SwarnadeepNandy @Palani Kumar 

8 REPLIES 8

@Santhosh15 

so did you try updating the script?

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

@Santhosh15 

Please update the script and let us know the status

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

Hello @Ankur Bawiskar ,

 

I have updated the script but approvers are not creating.

var NutChangeApprovalUtilsForImpactedCI = Class.create();
NutChangeApprovalUtilsForImpactedCI.prototype = {
initialize: function() {},
getApprovers: function(chgGR) {

var approvers = [];
var agGR1 = new GlideRecord('change_request');
agGR1.addQuery('sys_id', chgGR);
agGR1.query();
while (agGR1.next()) {
gs.log("change request" + agGR1.number);
gs.log('Critical CI' + agGR1.u_critical_impacted_services_cis.toString());
var agGR2 = agGR1.u_critical_impacted_services_cis.toString();
var tabs_array = agGR2.split(",");
for (var i in tabs_array) {
var agGR3 = new GlideRecord('cmdb_ci_appl');
agGR3.addQuery('sys_id', tabs_array[i]);
agGR3.query();
while (agGR3.next()) {
var assignment_group_name = agGR3.support_group.toString();
gs.log('assignment name is' + assignment_group_name);
var support_group = assignment_group_name.split(",");
gs.log("support group split" + support_group);
for (var j in support_group) {
var agGR4 = new GlideRecord('sys_user_group');
agGR4.addQuery('sys_id', support_group[j]);
agGR4.query();
if (!hasAlreadyApprovedLastApproval(agGR4.manager)) {
approvers.push(agGR4.manager);
gs.log("Testing for manager approver" + agGR4.manager);
if (!gs.nil(agGR4.u_sdm))
approvers.push(agGR4.u_sdm);
} else if (!gs.nil(agGR4.u_sdm)) {
approvers.push(agGR4.manager);
approvers.push(agGR4.u_sdm);
}
}
}
}
}
//has the user specified already made an approval on the current record
function hasAlreadyApprovedLastApproval(userSysId) {
if (gs.nil(userSysId))
return true;

var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('document_id', chgGR.getUniqueValue());
grApproval.addQuery('approver', userSysId);
grApproval.orderByDesc('sys_created_on');
grApproval.query();
return grApproval.next() && grApproval.getValue('state') === 'approved';
}
},

isApproved: function(chgGR) {

return "";
},

type: 'NutChangeApprovalUtilsForImpactedCI'
};



williamsmith262
Mega Contributor

It seems like you're facing an issue with dot-walking in ServiceNow's scripting environment. Specifically, you're trying to retrieve the assignment group for a change request using dot-walking, but it's not working as expected.

Based on the code snippet you provided, it appears that you're attempting to fetch the assignment group from the u_critical_impacted_services_cis field, which is a list collector field referencing the cmdb_ci_appl table. To retrieve the assignment group, you're trying to dot-walk through the support_group field.

Here are a few suggestions to help you troubleshoot and resolve this issue:

Field Mapping: Double-check the field mapping and relationships between the u_critical_impacted_services_cis field and the support_group field. Ensure that the dot-walking path is correctly defined in the field mapping.

Data Validation: Verify that the u_critical_impacted_services_cis field is populated correctly in your change request record. If it's empty or contains incorrect data, it could lead to issues when dot-walking.

Error Handling: Implement error handling and logging in your script to capture any errors or unexpected behavior. Use gs.log statements to log intermediate values and debug the dot-walking process.

Field Type: Ensure that the support_group field is indeed a reference field to the sys_user_group table. If it's not, dot-walking might not work as expected.

Script Execution: Make sure that your script is executed in the appropriate context and at the right time during the change request lifecycle to access the required data.

Testing: Test your script with different scenarios and data to identify any patterns or specific cases where the dot-walking fails.

If you continue to encounter issues, consider reaching out to your ServiceNow administrator or support team for further assistance. They can help you review your configuration and script to identify and resolve the problem.