Displaying Confirmation Message in SOW View while closing the case

vinnus
Tera Contributor

 

Currently, the confirmation message that appears when closing a case is only shown in the native view, not in the SOW view.

we want achieve UI page to confirm both the fields from case record while closing the case record we want populate those two fields in the confirmation message on click yes UI action will proceed and close the case if no abort the action and stays on the case record for the change of those fields. Thanks

 

 

vinnus_0-1753358084576.png

 

5 REPLIES 5

Shruti
Mega Sage
Mega Sage

Hi,

You can use g_modal API to display a modal window in workspace.

Go to System definition -> UI action

Open the UI action and make sure these checkboxes are checked

Shruti_0-1753359090992.png

Use g_modal API in workspace client script

Reference - https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

vinnus
Tera Contributor

Hi ,

UI Page:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:evaluate var="jvar_keyTheme" expression="RP.getParameterValue('sysparm_KeyTheme')"/>
<g:evaluate var="jvar_RootCause" expression="RP.getParameterValue('sysparm_RootCause')"/>


<p>Please click 'Yes' to acknowledge that the fields below are accurate:-</p>

<p><strong> Key theme: ${jvar_keyTheme} </strong></p>
<p><strong> Root Cause: ${jvar_RootCause}</strong></p>

<!--<p>Select OK to confirm the change</p> <p>Select Cancel to keep the original value.</p>-->

<g:ui_form>
<div class="modal-footer">
<span class="pull-right">

    <!--<button class="btn btn-default" id="cancel_button" onclick="window.GlideModalForm.prototype.locate(this).destroy(); doCancel(); return true" style="min-width: 5em;" title="" type="submit">-->
    <button class="btn btn-default" id="cancel_button" onclick="window.GlideModalForm.prototype.locate(this).destroy();  doRefresh(); return true" style="min-width: 5em;" title="" type="submit">
        No
        </button>
    <button class="btn btn-primary" id="ok_button" onclick="window.GlideModalForm.prototype.locate(this).destroy(); return true" style="min-width: 5em;" title="" type="submit">
        Yes
    </button>
</span>
</div>
    </g:ui_form>


</j:jelly>
 
Workspace Client Script:
function onClick(g_form) {
    g_form.clearMessages();
    g_form.removeDecoration('blocker', 'icon-alert', 'Blocker needs to be removed', 'color-red');

    var blocker = g_form.getValue('blocker');
    if (blocker == 'true') {
        g_form.addErrorMessage('Blocker needs to be removed for closing the case');
        g_form.addDecoration('blocker', 'icon-alert', 'Blocker needs to be removed', 'color-red');
        g_form.getControl('blocker').focus();
        return false;
    }

    // set the 'State' field to "Closed Incomplete"
    var state = g_form.getValue('state');

    if (state != 4) {
        g_form.setValue("state", 4); // Closed Incomplete
    }

    g_form.submit('close_incomplete_case'); // MUST call the 'Action name' set in this UI Action
}
  /*var ui_page_id = '53f3666b97200a508c8b76511153af2d';
    g_modal.showFrame({
        url: '/ui_page.do?sys_id=' + ui_page_id,
        //title: 'Choose a template',
        size: 's',
        height: 300
    }); */

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    serverCloseIncompleteCase();

function serverCloseIncompleteCase() {
    // var state = current.state;
    // if (state != 4) {
    //     current.state = 4;
    // }
    var state = g_form.getValue('state');

    if (state != 4) {
        g_form.setValue("state", 4); // Closed Incomplete
    }
    g_form.save();
}

RaghavSh
Kilo Patron

Did you add script to workspace client script section of your UI action.

 

Refer : https://www.servicenow.com/community/developer-forum/how-to-call-a-ui-page-by-ui-action-in-workspace... 


Raghav
MVP 2023

Ankur Bawiskar
Tera Patron
Tera Patron

@vinnus 

You can make your UI action as client side and ensure Onclick function is given

For native: script will be like this, I took example of OOTB "Close Task" button on sc_task

function closeTask() {

    var dialog = new GlideModal('glide_modal_confirm', true, 300);
    dialog.setTitle('Confirmation');
    dialog.setPreference('body', 'Are you sure?'); // here you can pass the form field value in body by accessing using g_form.getValue('fieldName')
    dialog.setPreference('focusTrap', true);
    dialog.setPreference('onPromptComplete', doComplete);
    dialog.setPreference('onPromptCancel', doCancel);
    dialog.render();

    function doComplete() {
        g_form.setValue('state', 3);
        //Call the UI Action and skip the 'onclick' function
        gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
    }

    function doCancel() {
        callback(false);
    }

}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    updateTask();

function updateTask() {
    current.state = 3;
    current.update();
}

AnkurBawiskar_0-1753361035050.png

 

For SOW -> use g_modal confirm API

g_modal : client 

function onClick(g_form) {

    var msg = getMessage("Are you sure you?"); // here you can pass the form field value in body by accessing using g_form.getValue('fieldName')
	
    g_modal.confirm(getMessage("Confirmation"), msg, function(confirmed) {
        if (confirmed) {
            g_form.setValue('state', 'closed_complete');
            g_form.save();
        }
    });

}

AnkurBawiskar_1-1753361185180.png

 

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