- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:14 AM
Hi All,
I am trying to create a UI action which should create an Incident from RITM form and I need help with showing up a confirmation box which asks for confirmation before proceeding with Yes/No.
If yes, it has to create Incident and If "no" it should stay on the same form/page
I know the below script I drafted below needs a lot of change. Please suggest the some solution for the same.
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
/* Construct comments and work notes
-----------------------------------------------------------------------------------------------------------------------*/
var comments = 'Incident created from ' + ritmNum;
function openinc() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse == 'false') {
return false; //Abort submission
} else
gsftSubmit(null, g_form.getFormElement(), 'transfer_incident');
}
if (typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode() {
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
//inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.cmdb_ci = current.cmdb_ci;
inc.assignment_group = current.assignment_group;
inc.business_service = current.business_service;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.description = current.variables.description;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
current.comments = 'RITM converted to ' + incNum + '. Please use this reference from now on.';
current.setValue('state', '10');
var mySysID = current.update();
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
action.setRedirectURL(inc);
}
TIA
@Ankur Bawiskar @Anand Kumar P @Runjay Patel @Ravi Gaurav
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:35 AM
Hi @DB1 ,
Use client script code like below.
function createIncident() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse)
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:24 AM
I hope you have this
1) client checkbox - true
2) onclick function - openinc()
Update script as this
function openinc() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse == 'false') {
return false; //Abort submission
} else
gsftSubmit(null, g_form.getFormElement(), 'transfer_incident');
}
if (typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode() {
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
var comments = 'Incident created from ' + ritmNum;
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
//inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.cmdb_ci = current.cmdb_ci;
inc.assignment_group = current.assignment_group;
inc.business_service = current.business_service;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.description = current.variables.description;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
current.comments = 'RITM converted to ' + incNum + '. Please use this reference from now on.';
current.setValue('state', '10');
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
action.setRedirectURL(inc);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:31 AM
Hi sir,
Thanks for the reply I tried the same it shows a popup with Yes/ Cancel and if I select cancel it still creates an Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:35 AM
Hi @DB1 ,
Use client script code like below.
function createIncident() {
var usrResponse = confirm('Are you sure you would like to proceed?');
if (usrResponse)
gsftSubmit(null, g_form.getFormElement(), 'create_incident');
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 06:38 AM
try this
function openinc() {
if(confirm('Are you sure you would like to proceed?'))
gsftSubmit(null, g_form.getFormElement(), 'transfer_incident');
else
return;
}
if (typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode() {
var ritmTable = current.getTableName();
var ritmSysID = current.getUniqueValue();
var ritmNum = current.getValue('number');
var comments = 'Incident created from ' + ritmNum;
var inc = new GlideRecord("incident");
inc.caller_id = current.request.requested_for;
//inc.assignment_group = assignmentGroup;
inc.short_description = current.short_description;
inc.cmdb_ci = current.cmdb_ci;
inc.assignment_group = current.assignment_group;
inc.business_service = current.business_service;
inc.impact = current.impact;
inc.urgency = current.urgency;
inc.description = current.variables.description;
inc.comments = comments;
inc.parent = ritmSysID;
var incSysID = inc.insert();
var incTable = inc.getTableName();
var incNum = inc.getValue('number');
GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
current.comments = 'RITM converted to ' + incNum + '. Please use this reference from now on.';
current.setValue('state', '10');
gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
action.setRedirectURL(inc);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader