Alert message not working in Workspace client script within UI action

AARTHI
Tera Contributor

I tried to use the below script in the workspace client script within the UI action. 

The expectation of the script is to check whether there are any child incidents available for the incident record. If it contains any(active/inactive) child incident, then it should popup the alert message and abort the ui action. If there are no child incidents , then it should popup the confirm message to proceed with the UI action fuction or not.

The below script doesn't work and not showing up the alert message in the Agent Workspace. But it works fine in ITIL native view.

This UI action runs on Incident table.

var chldinc = new GlideRecord('incident');
    chldinc.addQuery('sys_id', g_form.getUniqueValue());
    chldinc.addQuery('child_incidents', '>=', 1);
    chldinc.query();
    if (chldinc.next()) {
        var answer = alert("Child incidents are related to this incident, cannot be converted.");
        if (answer) {
            return false;
        }
    } else

        var answer1 = confirm("Do you want to create a new Adhoc?\nIf 'YES'click 'OK'\nIf 'NO'click 'Cancel'");

    if (answer1 == true) {
		 g_form.submit('create_ar');
        

    } else {
        return false;
    }
2 REPLIES 2

Fabian Kunzke
Kilo Sage
Kilo Sage

Hey,

this community post had a similar issue. I do belive that some javascript native functions don't work as intended in the workspace, confirm and alert being one of them.
Instead g_modal.confirm should do the trick.

Regards

Fabian

JamenW
Tera Expert

this worked!!

JamenW_0-1743625659713.png

 

 

 

function onClick(g_form) {

    if (g_user.userID != g_form.getValue('assigned_to')) {
         g_modal.alert('Only the assigned to can do this action.');
         return;
     }

    var msg = getMessage("Are you sure?");
    g_modal.confirm(getMessage("Confirmation"), msg, function(confirmed) {
        // if (confirmed) {
        //     g_form.setValue('state', 'closed_complete');
        //     g_form.save();
        // }
    });

    return false;
}