- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2019 02:27 PM
Hi guys,
I have a requirement where I need to make the 'Risk assessment' link available while submitting (before submitting or saving for the first time) the change form.
Here is the UI action but I am confused as to where to make the changes. Currently, the link shows after the change is submitted. Can someone pl help?
condition: gs.hasRole('itil') && new RiskCalculator(current).showRiskAssessment()
Script:
function invokeAssessment() {
new ChangeRiskUiActionControl().invokeAssessment();
}
var ChangeRiskUiActionControl = Class.create({
initialize: function() {
},
invokeAssessment: function() {
delete window.g_parentDialog;
g_form.hideAllFieldMsgs();
if (!g_form.submitted && g_form.modified)
this.handleDirtyForm();
else {
var changeRequestSysId = g_form.getUniqueValue();
var tableName = g_form.getTableName();
var ga = new GlideAjax("ChangeRiskAsmtAjax");
ga.addParam("sysparm_name", "invokeAssessmentAjax");
ga.addParam("sysparm_id", changeRequestSysId);
ga.addParam("sysparm_class", tableName);
ga.getXMLAnswer(this.processAsmt.bind(this));
}
},
deleteAsmt: function(asmtInstanceSysId) {
if (window.NOW.change_managment.riskAsmtAction === "delete") {
var ga = new GlideAjax("ChangeRiskAsmtAjax");
ga.addParam("sysparm_name", "deleteAsmtInstanceAjax");
ga.addParam("sysparm_id", asmtInstanceSysId);
ga.getXMLAnswer(function(answer){ });
} else if (window.NOW.change_managment.riskAsmtAction === "reload")
window.location.reload();
},
processAsmt: function(answer) {
answer = JSON.parse(answer);
if (!answer.hasAsmt)
g_form.addInfoMessage(getMessage("There are no risk assessments defined for this Change Request"));
else {
if (answer.asmtComplete)
this.handleCompletedAsmt();
else {
var asmtInstanceSysId = answer.asmtInstanceSysId;
var changeRiskAsmtSysId = answer.changeRiskAsmtSysId;
var changeRequestSysId = answer.changeRequestSysId;
var riskAsmtName = answer.riskAsmtName;
this.handleAsmt(asmtInstanceSysId, changeRiskAsmtSysId, changeRequestSysId, riskAsmtName);
}
}
},
handleDirtyForm: function() {
var dirtyFormUiPage = "change_risk_asmt_dirty_form_dialog";
var dialogWindow = new GlideModal(dirtyFormUiPage, false, "modal-md");
dialogWindow.setTitle(getMessage("Save changes"));
dialogWindow.setPreference("displayValue", g_form.getDisplayValue());
dialogWindow.render();
window.g_parentDialog = dialogWindow;
},
handleCompletedAsmt: function() {
var displayValue = g_form.getDisplayValue();
var completedAsmtUiPage = "change_risk_completed_asmt_dialog";
var dialogWindow = new GlideModal(completedAsmtUiPage, false, "modal-md");
dialogWindow.setTitle(getMessage("Risk Assessment Complete"));
dialogWindow.setPreference("displayValue", displayValue);
dialogWindow.render();
window.g_parentDialog = dialogWindow;
},
getEncodedUrl: function(changeRequestSysId, asmtInstanceSysId) {
var closeUiPage = "change_risk_asmt_close_dialog";
var url = "/" + closeUiPage + ".do";
url += "?sysparm_stack=no";
url += "&sysparm_id=" + changeRequestSysId;
url += "&sysparm_asmtInstanceSysId=" + asmtInstanceSysId;
return encodeURIComponent(url);
},
handleAsmt: function(asmtInstanceSysId, changeRiskAsmtSysId, changeRequestSysId, riskAsmtName) {
var asmtUiPage = "assessment_take2";
var url = asmtUiPage + ".do";
url += "?sysparm_assessable_sysid=" + asmtInstanceSysId;
url += "&sysparm_assessable_type=" + changeRiskAsmtSysId;
url += "&sysparm_hide_header=true";
url += "&sysparm_hide_save=true";
url += "&sysparm_hide_cancel=true";
url += "&sysparm_hide_source_details=true";
url += "&sysparm_stack=no";
url += "&sysparm_return_url=" + this.getEncodedUrl(changeRequestSysId, asmtInstanceSysId);
var dialogWindow = new GlideModal("change_risk_asmt_" + asmtInstanceSysId, false, "modal-lg");
dialogWindow.setTitle(riskAsmtName + "");
dialogWindow.setAutoFullHeight(true);
dialogWindow.setPreference("sysId", changeRequestSysId);
dialogWindow.on("beforeclose", this.deleteAsmt.bind(this, asmtInstanceSysId));
dialogWindow.renderIframe(url, function() {
$j("iframe[src*='" + asmtUiPage + ".do']").contents().find("td[class='spacerCellSmall']").each(
function(i,e) {
e.remove();
}
);
});
window.NOW.change_managment = { "riskAsmtAction" : "delete" };
window.g_parentDialog = dialogWindow;
},
type: "ChangeRiskUiActionControl"
});
Thanks much,
Archie
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 02:35 PM
This requirement is not possible as ServiceNow doesn't allow risk form to be submitted before Change is submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2019 02:51 PM
Earlier the condition was
'gs.hasRole('itil') && !current.isNewRecord() && new RiskCalculator(current).showRiskAssessment()'
I removed !current.isNewRecord() from it, but the link didn't show on new form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2019 04:16 PM
hi archie,
would like to try below script
var asmt = new GlideRecord('asmt_assessment_instance');
asmt.addQuery('u_task', current.sys_id);
asmt.addQuery('user', gs.getUserID());
asmt.addQuery('state', 'ready').addOrCondition('state', 'wip');
asmt.query();
if(asmt.next()){
var url = '/assessment_take2.do?sysparm_assessable_sysid=' + asmt.sys_id.toString() + '&sysparm_assessable_type=' + asmt.metric_type.toString();
gs.addInfoMessage("Any outstanding Risk & Impact assessments must be completed before this record can be progressed. You can view your outstanding assessments in the related list at the bottom of this form or click <a href= '" + url + "'>here</a> to fill out now.");
}
do let me know if this helps or this is what u wanted
[ Architect | Certified Professional]
Was this response helpful? If so, please mark it as ✅ Helpful and ✅ Accept as Solution to help others find answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2019 10:12 AM
Thanks Ajay.
So the UI Action is already set up (the script above). It is visible all the time EXCEPT when a new change form loads (before submitting or saving for first time). i need to show this form link when the form loads for the first time also.
So I removed the !current.isNewRecord() from the UI Action condition but it still didn't show up on new form. I think there is more to it, that's why I pasted the script above. Also, this script calls a UI page. Script below. There is a comment below (in red) that hides the form link on page loading but I am not sure what I need to modify in order to achieve that. Can you please guide me? Let me know if something needs to be clarified.
--------------------------------------------------------------
addLoadEvent(function() {
var displayValue = "";
if (window.parent && window.parent.g_parentDialog)
displayValue = window.parent.g_parentDialog.getPreference("displayValue");
else if (window.g_parentDialog)
displayValue = window.g_parentDialog.getPreference("displayValue");
$j("#dirty_form_modal_confirmation_description").text(
formatMessage(getMessage("Do you want to save changes to {0} before leaving this page?"), displayValue)
);
});
function save() {
if (g_form && g_form.mandatoryCheck() && (g_form.isNewRecord() || g_form.modified)) {
// Add a hidden parameter to indicate that the run risk assessment should be run after the form has saved
var afterSaveURL = new GlideURL();
if (g_form.isNewRecord())
afterSaveURL.setFromString(g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue());
else
afterSaveURL.setFromCurrent();
addHidden(g_form.getFormElement(), "sysparm_goto_url", afterSaveURL.getURL().replace("change_request.do", "change_run_risk_asmt.do"));
g_form.save();
}
else
GlideDialogWindow.get().destroy();
}
function cancel() {
GlideDialogWindow.get().destroy();
}
-------------------------------------------------------------------
Archie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 02:35 PM
This requirement is not possible as ServiceNow doesn't allow risk form to be submitted before Change is submitted.