Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

UI action in wokspace

Rosy14
Kilo Sage

I want to show a pop-up if there are related tasks before closing the parent case.

The below code is working for native UI but how to add the same functionality in workspace? Need the same feature of "global.StateFlow().processFlow" in workspace as well.

 

Rosy14_0-1788178166441.png

 

function runClientCode() {

    if (!g_form.getValue("assigned_to")) {
        g_form.addErrorMessage('Assigned To cannot be empty. Please fill the Assign To field before moving the request to Awaiting Info or Resolved.');
        return false;
    }

    var gaCheck = new GlideAjax("sn_customerservice.CheckTaskRecord");
    gaCheck.addParam('sysparm_name', 'checkIfTask');
    gaCheck.addParam('sysparm_request_id', g_form.getUniqueValue());
    gaCheck.getXMLAnswer(function(response) {

        if (response == "1") {
            if (confirm("Resolution of request will close all open tasks. Do you want to proceed?")) {
                var gaResolve = new GlideAjax("sn_customerservice.CheckTaskRecord");
                gaResolve.addParam('sysparm_name', 'closeTaskRecord');
                gaResolve.addParam('sysparm_request_id', g_form.getUniqueValue());

                gaResolve.getXMLAnswer(function(answer) {
                    if (answer == "1") {
                        g_form.addInfoMessage("test4");
                        gsftSubmit(null, g_form.getFormElement(), 'proposeSolution');
                    }
                });
            } else
                return false;
        } else
            gsftSubmit(null, g_form.getFormElement(), 'proposeSolution');
    });
}

if (typeof window == 'undefined') {
    runServerCode();
}

function runServerCode() {
    new global.StateFlow().processFlow(current, 'sys_id', 'manual');
}

 

1 REPLY 1

Ankur Bawiskar
Tera Patron

@Rosy14 

Ensure these 2 checkboxes are selected and add script in workspace client script

AnkurBawiskar_0-1788178753438.png

 

You can check OOTB UI actions and add the code accordingly

AnkurBawiskar_1-1788178846590.png

Something like this in workspace client script

function onClick(g_form) {
    if (!g_form.getValue("assigned_to")) {
        g_form.addErrorMessage('Assigned To cannot be empty. Please fill the Assign To field before moving the request to Awaiting Info or Resolved.');
        return false;
    }

    var gaCheck = new GlideAjax("sn_customerservice.CheckTaskRecord");
    gaCheck.addParam('sysparm_name', 'checkIfTask');
    gaCheck.addParam('sysparm_request_id', g_form.getUniqueValue());
    gaCheck.getXMLAnswer(function(response) {

        if (response == "1") {
            if (confirm("Resolution of request will close all open tasks. Do you want to proceed?")) {
                var gaResolve = new GlideAjax("sn_customerservice.CheckTaskRecord");
                gaResolve.addParam('sysparm_name', 'closeTaskRecord');
                gaResolve.addParam('sysparm_request_id', g_form.getUniqueValue());

                gaResolve.getXMLAnswer(function(answer) {
                    if (answer == "1") {
                        g_form.addInfoMessage("test4");
                        g_form.submit('proposeSolution');
                    }
                });
            } else
                return false;
        } else
            g_form.submit('proposeSolution');
    });
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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