Custom UI Acton - UI Modal is not running code after confirmation

IndianaJones
Tera Expert

I have a made a custom UI action to convert an Incident over to a case. This works fine in the platform and workspace as long as I use a basic "confirm" prompt, but I was hoping to use a modal. My issue is that the modal closes and nothing happens. Is there something I'm missing on code with my modal? The reason this is in a UI action is because a number of our users are not using workspace. 

 

UI action settings

IndianaJones_0-1688994325643.png

 

UI action Script:

 

//Run Client-side 'onclick' function
function createCase() {
    var usrResponse = confirm('Are you sure you want to transfer this to a case? This will auto close the Incident and create a new case record.');
    if (usrResponse == true) {
        g_form.setValue('comments'"Incident is being closed and transferred to lending support team as a case");
        gsftSubmit(null, g_form.getFormElement(), 'createcase'); 
    }
    else
    {
        return false;
    }
}
 
if (typeof window == 'undefined')
    createCaseServer();

//Server-side function
function createCaseServer() {
    var gr = new GlideRecord('sn_customerservice_case');
    gr.short_description = current.short_description;
    gr.description = current.description;
    gr.work_notes = "Case created from record: " + current.number;
    var customerservicecase = gr.insert();

    GlideSysAttachment.copy('incident', current.sys_id, 'sn_customerservice_case', customerservicecase); //copies attachment if any can be commented if required.

    current.update();

    action.setRedirectURL(gr);
}

 

 

Workspace Client Script (this one does NOT work):

 

function onClick(g_form) {
    var msg = getMessage("Are you sure you want to transfer this to a case? This will auto close the Incident and create a new case record.");
    g_modal.confirm(getMessage("Confirmation"), msg, function(confirmed) {
        if (confirmed) {
            //is not working below
            var actionName = g_form.getActionName();
            g_form.submit(actionName);
        }
    });
}
 
 
Workspace Client Script that DOES work:
function onClick(g_form) {
 var usrResponse = confirm('Are you sure you want to transfer this to a case? This will auto close the Incident and create a new case record.');
    if (usrResponse == true) {
        var actionName = g_form.getActionName();
        g_form.submit(actionName);
    }
}

 

1 REPLY 1

IndianaJones
Tera Expert

Either there is a bug or I do not understand where the association is being lost. But the fix is to directly call the action name rather than using g_form.submit(g_form.getActionName());. As a test I directly called my action name from the modal confirmation and it worked just fine. I went back and set the comment of the Incident to the action name that is called from g_form.getActionName() and it returned a value of "none".

 

Code snippet from my workspace client script.

IndianaJones_0-1689022792264.png

 

Comment value in workspace.

IndianaJones_1-1689022828835.png