Client & Server code in UI Action

Nicola Attico
ServiceNow Employee
ServiceNow Employee

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

find_real_file.png

When I hit the button, the code executes the client-side (alert), but never executes the gs.error command.

 

Thanks,

Nicola

9 REPLIES 9

Musab Rasheed
Tera Sage
Tera Sage

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

Please hit like and mark my response as correct if that helps
Regards,
Musab

Akash4
Kilo Sage
Kilo Sage

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

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Aman Kumar S
Kilo Patron

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 🙂

Best Regards
Aman Kumar

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.

Best Regards
Aman Kumar