run server script via workspace client script in UI Action

Hyohyeon Kim
Tera Contributor

Hi Experts.

I'm trying to custom modal box for review additional comments with [Save] UI Action. (button)
I expected to Serverside Script will run after Workspace Client Script running But it doesn't work. (debug alert does not appeared)
As above I need to change OOTB [Save] action and modify script like below

Script:

if (typeof window == 'undefined')
    afterCommentCheckModal();

function afterCommentCheckModal() {
    current.update();

    // Track number of cases that are updated via CSM Agent Workspace
    var csmWorkspaceUAUtil = new sn_csm_workspace.CSMWorkspaceUAUtil();
    csmWorkspaceUAUtil.updateCase(current.sys_id);
	alert('!!!!!!!!!!'); // **for debug alert**
}


Workspace Client Script:

function onClick(g_form) {
	var act = g_form.getActionName();
	alert(act);
    var comm = g_form.getValue('comments');
    var fields = [{
        type: 'textarea',
        name: 'comments',
        label: getMessage('comments'),
        value: comm
    }];
    if (comm) {
        g_modal.showFields({
            title: "check additional comment",
            fields: fields,
            size: 'lg'
        }).then(function(fieldValues) {
            g_form.setValue('comments', fieldValues.updatedFields[0].value);
            g_form.submit(act);
        });
    } else {
		g_form.submit(act);
    }
}


cf. I've already checked community questions & Knowledges below

How to use client script and server script for Agent workspace UI action - Service Management - Ques...

Client & Server Code in One UI Action - ServiceNow Guru

gsftSubmit UI Action not working - Developer Community - Question - ServiceNow Community

 

Thanks.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Hyohyeon Kim ,

You can use the g_form.submit to run the server side of ui action

 g_form.submit(g_form.getActionName());

It will resolve the issue 

find_real_file.png

OR

Rather than calling g_form.getActionName() we can directly pass the action name.

g_form.submit('action_name');

Here is an sample:

function onClick(g_form) {

    var fields = [{
        type: 'reference',
        name: 'u_duplicate_incident',
        label: getMessage('Duplicate Incident'),
        mandatory: true,
        reference: 'incident',
        referringTable: 'incident',
        referringRecordId: g_form.getUniqueValue()
    }];

    g_modal.showFields({
        title: "Provide Duplicate Incident",
        fields: fields,
        size: 'sm'
    }).then(function(fieldValues) {
        g_form.setValue('close_code', 'Duplicate Incident');
        g_form.setValue('close_notes', 'This is a duplicate Incident');
		g_form.setValue('short_description', "Duplicate Incident -" + g_form.getValue('short_description'));
        g_form.setValue('u_duplicate_incident', fieldValues.updatedFields[0].value);
		g_form.submit('validate_check_duplicate');
    });
}

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

 

 

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hi @Hyohyeon Kim ,

You can use the g_form.submit to run the server side of ui action

 g_form.submit(g_form.getActionName());

It will resolve the issue 

find_real_file.png

OR

Rather than calling g_form.getActionName() we can directly pass the action name.

g_form.submit('action_name');

Here is an sample:

function onClick(g_form) {

    var fields = [{
        type: 'reference',
        name: 'u_duplicate_incident',
        label: getMessage('Duplicate Incident'),
        mandatory: true,
        reference: 'incident',
        referringTable: 'incident',
        referringRecordId: g_form.getUniqueValue()
    }];

    g_modal.showFields({
        title: "Provide Duplicate Incident",
        fields: fields,
        size: 'sm'
    }).then(function(fieldValues) {
        g_form.setValue('close_code', 'Duplicate Incident');
        g_form.setValue('close_notes', 'This is a duplicate Incident');
		g_form.setValue('short_description', "Duplicate Incident -" + g_form.getValue('short_description'));
        g_form.setValue('u_duplicate_incident', fieldValues.updatedFields[0].value);
		g_form.submit('validate_check_duplicate');
    });
}

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

 

 

Hi,  @Sandeep Dutta 
Thanks for your reply.

I try to just as you solution, but it doesn't work yet.
alert for debug not appeared.

How can I check excution of server side scirpt?


**screenshot below

find_real_file.png