Client & Server Side Script via Form Action (Workspace) possible like via ui action???

Zod
Giga Guru

Hi everyone,

I’m trying to create a button in Workspace that performs client-side validation (e.g., checking field values) and only executes server-side logic if all client-side checks pass.

In classic forms, this is straightforward with UI Actions. However, in Workspace, using Form Actions feels more complex, and it seems like buttons are either purely client-side or server-side.

What I’m trying to achieve (simplified example):

  • If current.variable('abc') == "true" → execute server-side logic (e.g., set current.status = 3 and update the record)
  • Otherwise → stay on the client side and show an error message (g_form.showErrorMessage('Error'))

What’s the recommended approach to implement this in Workspace? Is there a way to combine client-side validation with conditional server-side execution in a single button?

 

ChatGPT doesn’t really help me here — I need an answer from someone with real hands-on experience.

Thank you.

1 ACCEPTED SOLUTION

Zod
Giga Guru

Thx to all. Not working with Builder so far due to limitations (like most of the new stuff… mostly the f*cking FLOW BS — loved my workflow ), but ok — can’t turn back time

 

I was NOT aware of the workspace part after the script field in the UI Action for Workspace…!!

That is doing the trick.

 

So ... UI Action as usual with client and server-side coding via…

 

// client side checks before ...

...

 

//serverside

if (typeof window == 'undefined') {
current.status = 3; 
current.update();
action.setRedirectURL(current);
}

... and workspace part adding the same ... and at the end the action is called witch is only set in the upper script filed.

 

function onClick() { var test = g_form.getValue('test'); g_form.clearMessages(); if (!test) { g_form.addErrorMessage(getMessage('test_msg')); return false; } g_form.setValue('approval', 'rejected'); g_form.submit('my_action_name'); // Action name }

 

 

Works now. 

 

View solution in original post

4 REPLIES 4

iftekharmir
Tera Contributor

Hi @Zod ,

You can achieve this in Workspace

Approach: UI Action + GlideAjax (Script Include)

  1. Create a UI Action for your button.

  2. Perform all validations using g_form on the client side.

  3. Only if validation passes, invoke a GlideAjax call to a client-callable Script Include.

  4. Execute your server-side logic in the Script Include (e.g., updating the record).

Example:

Client-side (Form Action):

function onClick(g_form) {

    var abc = g_form.getValue('variables.abc');

    // Client validation
    if (abc != 'true') {
        g_form.addErrorMessage('Error: ABC must be true');
        return;
    }

    // Server call
    var ga = new GlideAjax('MyWorkspaceAction');
    ga.addParam('sysparm_name', 'processRecord');
    ga.addParam('sysparm_sys_id', g_form.getUniqueValue());

    ga.getXMLAnswer(function(response) {
        if (response === 'success') {
            g_form.addInfoMessage('Record updated successfully');
            g_form.reload();
        } else {
            g_form.addErrorMessage('Server error occurred');
        }
    });
}

Server-side (Script Include, client callable):

var MyWorkspaceAction = Class.create();
MyWorkspaceAction.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    processRecord: function() {
        var sysId = this.getParameter('sysparm_sys_id');

        var gr = new GlideRecord('your_table');
        if (gr.get(sysId)) {
            gr.status = 3;
            gr.update();
            return 'success';
        }
        return 'error';
    }
});

Key Notes:

  • GlideAjax is the standard way to bridge client and server.

  • Use g_form.addErrorMessage() instead of showErrorMessage() in Workspace.

  • For variables, use g_form.getValue('variables.<name>').

This pattern gives you full control over validation while still allowing conditional server execution, and aligns with how Workspace is designed to work.

tejarekanda
Tera Expert

Hi @Zod ,
1. Create an Ui action which will execute on client side by checking the client check box.

2. Then Check the Workspace Form Button check box.

3. There write the client script to check the validations and write the script include to perform the server side action.
4. And add the workspace view in the UI Action Visibility.

If my response helped, mark it as helpful and accept the solution.
Regards.

Henalu
Tera Contributor

Hi! In Breaking Trail I have a few articles that should guide you through this:

Primary:
Experience Restricted y Dynamic Evaluation en Declarative Actions — This covers exactly what you're trying to achieve: validation constraints in Workspace and why server-side validation is the recommended approach for conditional logic execution.

Complementary reads:

  1. El patrón de herencia de Declarative Actions — Shows you how Action Name works as a configuration key, which is useful when you need conditional logic based on record state.

  2. Cómo llamar a un Script Include desde un Client Script de UI Builder — Once you understand the validation pattern, this explains how to structure your server-side logic cleanly using Script Includes (reusable approach across client-side calls).

Start with the first one — it directly addresses your use case. The other two will help you architect the solution properly.

Zod
Giga Guru

Thx to all. Not working with Builder so far due to limitations (like most of the new stuff… mostly the f*cking FLOW BS — loved my workflow ), but ok — can’t turn back time

 

I was NOT aware of the workspace part after the script field in the UI Action for Workspace…!!

That is doing the trick.

 

So ... UI Action as usual with client and server-side coding via…

 

// client side checks before ...

...

 

//serverside

if (typeof window == 'undefined') {
current.status = 3; 
current.update();
action.setRedirectURL(current);
}

... and workspace part adding the same ... and at the end the action is called witch is only set in the upper script filed.

 

function onClick() { var test = g_form.getValue('test'); g_form.clearMessages(); if (!test) { g_form.addErrorMessage(getMessage('test_msg')); return false; } g_form.setValue('approval', 'rejected'); g_form.submit('my_action_name'); // Action name }

 

 

Works now.