- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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., setcurrent.status = 3and 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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7m ago
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
... 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Zod ,
You can achieve this in Workspace
Approach: UI Action + GlideAjax (Script Include)
Create a UI Action for your button.
Perform all validations using
g_formon the client side.Only if validation passes, invoke a GlideAjax call to a client-callable Script Include.
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 ofshowErrorMessage()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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
56m ago
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:
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7m ago
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
... 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.
