How to use both client and server side code in declarative action

Sachin G K1
Kilo Sage

Hey all,

 

I have a ui action(find the code below), which is working as expected. And it contains both server side and client side script. I wish to configure same functionality in workspace as well. So i have decided to go with declarative action.

 

What type of declarative action i should use and how to use both server and client side script in declarative action.

 

Ui Action: 

 

function checkList() {
    if (g_list.getChecked() !== '') {
        var ids = g_list.getChecked();
        var ga = new GlideAjax('ComplianceControlStateUpdater');
        ga.addParam("sysparm_name", "updateControlStateAndNotify");
        ga.addParam('sys_id', ids);
        ga.getXML(res);
    }

    function res(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
       
    }

    g_list.action('eee0ef221bde921076d6ed74604bcb11', 'group_attest');
}
if (typeof window == 'undefined') {
    server();
}

function server() {
    if (new sn_compliance.ControlRequirementUtils().controlToCRsM2mExistsForQuery({
            "control": current.getUniqueValue(),
            "control_requirement.state": "retired"
        })) {
        gs.addErrorMessage(gs.getMessage('One or more requirement is in retired state.'));
    } else {

        var isList = action.getGlideURI().get('sys_is_list');
        if (!isList) //Not from list form
            action.setRedirectURL(current);
    }
}
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Sachin G K1 

what's your business requirement?

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

hi @Ankur Bawiskar ,
Thanks for responding, please find details below:

 

The task is to create a UI action called "Group Attest" in the "Downstream Control" related list of the entity. This UI action should only be visible within the related list, not within the individual control records.

 

Functionality:

  • The "Group Attest" UI action should allow users to select multiple controls within the related list.
  • The system will then check the state of each selected control.
  • If any of the selected controls are in the Draft state, the system will move them to the Attest state.
  • Once the controls are moved to the Attest state, a notification will be sent to the Entity Owner to inform them of the change.

Issue in Workspace View:

The functionality works as expected in the native view. However, in the workspace view, the "Group Attest" UI action is not appearing in the related list as intended.

Steps attempted:

  • I checked the "Workspace Form Button" and "Workspace Form Menu" checkboxes in the UI action settings. As a result, the "Group Attest" UI action is now showing up in the Control Record itself, rather than in the "Downstream Control" related list.

However, in the declarative action setup, there is an option to define where the UI action should be displayed, which can resolve the issue. But i am not aware on how to use server side and client side script in same declarative action

Ui action:

SachinGK1_0-1733924569067.png

SachinGK1_1-1733924600883.png


Entity record:

SachinGK1_2-1733924742798.png

 




Ankur Bawiskar
Tera Patron
Tera Patron

@Sachin G K1 

you will lot of OOB UI actions where you can run both Client + Server in UI action in configurable workspace

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