Risk Assessment(atf)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I am writing a server-side script in the Change module to complete the Risk Assessment using ATF.When I tried to pass the sys_id from the Click a UI Action step (where the Change record is created), I received the error: "Change record not returned from ATF step".
However, when I use the same step as a reference in the Open an Existing Record step, it successfully opens the Change record that was created. But I am unable to fetch the sys_id in the ATF server-side script.Below is my code. Could someone please suggest a solution?
If this is an ATF limitation, I will raise a ticket with ServiceNow.
" var changeStep = steps('give your _SYSID');
if (!changeStep || !changeStep.record_id) {
stepResult.setOutputMessage("Change record not returned from ATF step");
return false;
}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
hi @kishorek9987311 ,
can you try below code
var queryStep = steps('bf4a3c45c3d33610c7311412b401310e').record_id; //replace your step sys_id
var changeSysId = queryStep;
if (!changeSysId) {
stepResult.setOutputMessage("Failed to find the Change record via Record Query step.");
stepResult.setSuccess(false);
return;
}
// Now you can use changeSysId to perform your Risk Assessment logic
var gr = new GlideRecord('change_request');
if (gr.get(changeSysId)) {
stepResult.setSuccess(true);
}
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
hi @Bhavya11
thanks for the replay above code was working fine but i am unable to submit the risk assessment as it was showing error below was the code i have used "
"
(function(outputs, steps, stepResult, assertEqual) {
// Replace 'STEP_3_SYS_ID' with the actual sys_id of your Step 3
var step3Id = ('1acf00b78783f2d082d933b40cbb3510');
var changeId = steps(step3Id).first_record;
// DIAGNOSTIC CHECK: This prints to the ATF Result Log
if (!changeId) {
stepResult.setFailedMessage("Diagnostic Failed: changeId is null or undefined. Check Step 3 Sys ID.");
return false;
} else {
gs.addInfoMessage("ATF Diagnostic: Found Change ID: " + changeId);
}
// ... rest of your script ...
var metricType = '0fda2a42831a725030a098747daad37b';
var userID = gs.getUserID();
var assessmentAPI = new SNC.AssessmentCreation();
var assessmentDetails = assessmentAPI.createAssessments(
metricType,
changeId,
userID,
false,
""
);
if (!assessmentDetails) {
stepResult.setOutputMessage("Assessment creation failed");
return false;
}
var instanceID = assessmentDetails.split(",")[0];
var qGR = new GlideRecord('asmt_assessment_instance_question');
qGR.addQuery('instance', instanceID);
qGR.query();
while (qGR.next()) {
var metric = qGR.metric.name.toString();
if (metric.includes("Complexity"))
qGR.value = "Easy";
else if (metric.includes("Criticality"))
qGR.value = "Less Critical";
else if (metric.includes("Redundancy"))
qGR.value = "No";
else if (metric.includes("Dependency"))
qGR.value = "No";
else if (metric.includes("downtime"))
qGR.value = "No";
qGR.update();
}
var instGR = new GlideRecord('asmt_assessment_instance');
if (instGR.get(instanceID)) {
instGR.state = "complete";
instGR.task = changeId.record_id;
instGR.update();
}
var riskResult = new ChangeRiskAsmt().calculateRisk(changeGR);
if (riskResult && riskResult.riskUpdated) {
changeId.risk = riskResult.risk;
changeId.update();
stepResult.setOutputMessage("Risk updated to: " + riskResult.risk);
} else {
stepResult.setOutputMessage("Risk calculation executed");
}
return true;
})(outputs, steps, stepResult, assertEqual); "
can you help me how to resolve it .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @kishorek9987311 ,
The Error occurred because 'ChangeGR' is not defined, After reviewing your script there is no reference to this 'ChangeGR' however 'chagneId'is available.
Updating the parameter from ChangeGR to changeId should resolve the issue.
var riskResult = new ChangeRiskAsmt().calculateRisk(changeGR);
"
(function(outputs, steps, stepResult, assertEqual) {
// Replace 'STEP_3_SYS_ID' with the actual sys_id of your Step 3
var step3Id = ('1acf00b78783f2d082d933b40cbb3510');
var changeId = steps(step3Id).first_record;
// DIAGNOSTIC CHECK: This prints to the ATF Result Log
if (!changeId) {
stepResult.setFailedMessage("Diagnostic Failed: changeId is null or undefined. Check Step 3 Sys ID.");
return false;
} else {
gs.addInfoMessage("ATF Diagnostic: Found Change ID: " + changeId);
}
// ... rest of your script ...
var metricType = '0fda2a42831a725030a098747daad37b';
var userID = gs.getUserID();
var assessmentAPI = new SNC.AssessmentCreation();
var assessmentDetails = assessmentAPI.createAssessments(
metricType,
changeId,
userID,
false,
""
);
if (!assessmentDetails) {
stepResult.setOutputMessage("Assessment creation failed");
return false;
}
var instanceID = assessmentDetails.split(",")[0];
var qGR = new GlideRecord('asmt_assessment_instance_question');
qGR.addQuery('instance', instanceID);
qGR.query();
while (qGR.next()) {
var metric = qGR.metric.name.toString();
if (metric.includes("Complexity"))
qGR.value = "Easy";
else if (metric.includes("Criticality"))
qGR.value = "Less Critical";
else if (metric.includes("Redundancy"))
qGR.value = "No";
else if (metric.includes("Dependency"))
qGR.value = "No";
else if (metric.includes("downtime"))
qGR.value = "No";
qGR.update();
}
var instGR = new GlideRecord('asmt_assessment_instance');
if (instGR.get(instanceID)) {
instGR.state = "complete";
instGR.task = changeId.record_id;
instGR.update();
}
var riskResult = new ChangeRiskAsmt().calculateRisk(changeGR);// this is issue try with this changeId
if (riskResult && riskResult.riskUpdated) {
changeId.risk = riskResult.risk;
changeId.update();
stepResult.setOutputMessage("Risk updated to: " + riskResult.risk);
} else {
stepResult.setOutputMessage("Risk calculation executed");
}
return true;
})(outputs, steps, stepResult, assertEqual); "
Try to fix this and try once again.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi @kishorek9987311 ,
did you try above approach?.
Thanks,
BK
