How to get the dot walking field value on workflow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 01:04 AM - edited 09-18-2023 01:05 AM
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:
==============
Thank you all in advance
@Maik Skoddow @Ankur Bawiskar @Samaksh Wani @SwarnadeepNandy @Palani Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 02:26 AM
so did you try updating the script?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 03:08 AM
Please update the script and let us know the status
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 02:05 AM - edited 09-21-2023 02:07 AM
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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 02:21 AM
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.