Pop Up confirmation message in UI action does not work for creating incident

Radhika1
Tera Contributor

Hi,

I have created a UI action 'Create Incident' on the HR case and it was working fine. Additionally, I wanted to add a pop-up confirmation message and clicking OK should let the user create an incident or else stay on the same form. But this code does not run and clicking on UI action is not creating any incident. Please have a look at the code I used below and help me understand what is wrong with it.

/****************************************************************************************************************?

function createInci() {
    var answer = confirm("Are you sure that you want to go ahead with creating an incident");
    if (answer == 'true') {
        gsftSubmit(null, g_form.getFormElement(), 'createInc');
    } else {
        return false;
    }
 
if (typeof window == 'undefined')
   resolveIncidentFunction();
function resolveIncidentFunction() {
    var gr = new GlideRecord('incident');
    gr.caller_id = current.opened_for;
    gr.short_description = current.short_description;
    gr.description = current.rich_description;
    var inc = gr.insert();
 
    GlideSysAttachment.copy('sn_hr_core_case', current.sys_id, 'incident', inc); //copies attachment if any can be commented if required.
       current.update();
 
    action.setRedirectURL(gr);
}
}
 
Please have a look at the screenshots of the UI action below:
 
Radhika1_0-1689152700477.png

 

 

Radhika1_1-1689152734659.png

 

 

Thanks in Advance,

RS

 

 

 

11 REPLIES 11

Harshad Wagh
Tera Guru

I think you are missing this statement.

gr.initialize();

 

can you please try with below code?

function createInci() {
    var answer = confirm("Are you sure that you want to go ahead with creating an incident");
    if (answer == 'true') {
        gsftSubmit(null, g_form.getFormElement(), 'createInc');
    } else {
        return false;
    }
 
if (typeof window == 'undefined')
   resolveIncidentFunction();
function resolveIncidentFunction() {
    var gr = new GlideRecord('incident');
    gr.initialize();
    gr.caller_id = current.opened_for;
    gr.short_description = current.short_description;
    gr.description = current.rich_description;
    var inc = gr.insert();
 
    GlideSysAttachment.copy('sn_hr_core_case', current.sys_id, 'incident', inc); //copies attachment if any can be commented if required.
       current.update();
 
    action.setRedirectURL(gr);
}
}

 

Harshad,

Thank You for the suggestion. I tried but it did not work.

do you see any error? if you go to incident table does it show any new records?

 

Can you please update the script and see if there are any logs getting generated?

function createInci() {
    var answer = confirm("Are you sure that you want to go ahead with creating an incident");
    if (answer == 'true') {
        gsftSubmit(null, g_form.getFormElement(), 'createInc');
    } else {
        return false;
    }
 
if (typeof window == 'undefined')
   resolveIncidentFunction();
function resolveIncidentFunction() {
    var gr = new GlideRecord('incident');
    gr.initialize();
    gr.caller_id = current.opened_for;
    gr.short_description = current.short_description;
    gr.description = current.rich_description;
    var inc = gr.insert();
 gs,log("POPUP" + inc );
    GlideSysAttachment.copy('sn_hr_core_case', current.sys_id, 'incident', inc); //copies attachment if any can be commented if required.
       current.update();
 
    action.setRedirectURL(gr);
}
}

Harshad, Yes I used info messages and found that the server-side script is not running.

And no incident was created in the backend either.