UI action with confirmation pop up

DB1
Tera Contributor

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 

1 ACCEPTED SOLUTION

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

-------------------------------------------------------------------------

View solution in original post

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on
7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@DB1 

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.

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

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

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

-------------------------------------------------------------------------

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on

@DB1 

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.

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