Executing both server and client-side scripts via a UX Form Action

Mahesh_Krishnan
Giga Guru

Hello there!

As I work on migrating from the Classic UI to the Workspace I am now facing a challenge is executing both client-side as well as server-side scripts via a single action. Here is the use case.

 

In the classic UI we have always been able to execute both scripts via a Client UI Action by using the following script to transfer control from the client script to the server script:

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

Well, I am trying to do the same thing in UI Builder but because the "window" command is not supported in UI Builder it has become challenging. 

What I need to accomplish is when a user selects the Form Action (whether it is mapped to an existing UI Action or uses a Declarative Action) is to run some client-side form validations to ensure all the fields are populated and then trigger a subflow.

I tried something simple in the UI Action form: I added a simple client-side script to the "Workspace Client Script" box as shown below:

function onClick() {
    g_form.hideAllFieldMsgs();

    var error = 'false';

    if (g_form.getValue("opportunity_id") == "") {
        error = 'true';
        g_form.showFieldMsg('opportunity_id', getMessage('Opportunity ID is required.'), 'error', false);
    }

    if (error == 'true') {
        return false;
    }

    gsftSubmit(null, g_form.getFormElement(), 'invite_to_apply');
	
}

and then added the following in the regular script box:

var gr = new GlideRecord('x_cpts_onboarding_cpts_referral_data');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if (gr.next()) {
	gr.account_opener_name = 'Maheshy';
}

The client-side executes fine but the server script did not execute at all. The Client field on the UI Action form is checked as well as the Workspace Form button.

I assume this is not how the UI Action is supposed to work but I thought I would give it a shot.

I am also researching how I can use Declarative Actions, mapping to a Event Handler etc. etc. by reviewing some existing examples on my PDI but quite frankly getting a bit lost.

If someone has attempted that I am trying to do and can give me some pointers that would help tremendously!

Thanks in advance!

Mahesh

1 REPLY 1

pavan_yakkala1
ServiceNow Employee
ServiceNow Employee

Hello Mahesh,

 

Can you please let me know if any lead on this? am also trying many options to achieve this but no luck so far