Client & Server code in UI Action

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 03:45 AM
Hi,
I'm probably missing something very basic here but I'm not able to execute both client and server side code in my UI Action
This is the script:
function doClient() {
alert("here " + g_form.getFormElement())
gsftSubmit(null, g_form.getFormElement(), "server_side");
}
if (typeof(window) == undefined) {
doServer()
}
function doServer() {
gs.error("server")
action.setRedirectURL(current)
}
This is how the UI action is set up
When I hit the button, the code executes the client-side (alert), but never executes the gs.error command.
Thanks,
Nicola

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 03:50 AM
Hello,
Not sure if gs.error exist but can you try below any method in server code ?
- gs.addInfoMessage
- gs.addErrorMessage
here is the example of client and server side code
https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 07:18 AM
Hello,
You can use the below for server-side and client-side respectively. In the code above as the doServer() function is run on the Server side, please use either of the first two lines (as suggested by Masub)
//Used in doServer() function
gs.logError('Way1 Error on Server Side');
gs.addInfoMessage('Way2 Error on Server Side');
//Below is the code to be used in doClient() function
g_form.addErrorMessage('Client Side This is an error');
Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 07:26 AM
Hey,
I think gs.error() doesn't work as info or error messages, you have to use addInfoMessage in order to achieve that.
Refer to below article to understand how exactly gs.error works, go through all responses.
gs warn/error/info compared to gs log
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 11:27 AM
Hey,
Didn't hear back on this.
Is your issue resolved? If yes, feel free to mark helpful/correct, so it will be helpful for others looking for similar query.
Aman Kumar