Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Call UI action server script from workspace client script

Vikram3
Tera Guru

Hi,

Below is the workspace client script which I am using on a UI action,

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.save();
    });
}

Right now I use g_form save() to save the form which I don't recommend to do that. I need to resolve the incident from ui action once client script job is done. 

1 ACCEPTED SOLUTION

Vikram3
Tera Guru

It worked.

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

g_form.submit('action_name');

In my case below is the final code,

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');
    });
}

View solution in original post

6 REPLIES 6

Hi,

It just saves the form. I need to resolve the incident.

Vikram3
Tera Guru

It worked.

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

g_form.submit('action_name');

In my case below is the final code,

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');
    });
}