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

Ankur Bawiskar
Tera Patron
Tera Patron

@Nicola Attico 

gs.error() should work fine

I did some small changes; please check if it works fine

function doClient() {
	alert("here " + g_form.getFormElement());
	gsftSubmit(null, g_form.getFormElement(), "server_side");
}

if (typeof(window) == undefined) {
	doServer();
}

function doServer() {
	gs.addErrorMessage("server");
	action.setRedirectURL(current);
}

Regards
ankur

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

@Nicola Attico 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

Hi, no, I don't see any change. While the client-side is executed, it seems like the server-side of the UI action is never executed. I think gs.error of gr.addErrorMessage doesn't make much difference...

Hi,

 

can call the servers script from client script in UI action ?

rubenferrero
Tera Contributor

Hi,

 

It's an old question, but in case somebody has the same issue.

 

The type for "undefined" in the "if" statement must be a String:

 

if (typeof(window) == "undefined") {

 

Best regards.