Server side code is not running after client script in UI action

chandan15
Tera Contributor

Hi, 

We had a cancel button for "dmn_demand" table to cancel the record by change the state->cancel.

I want to add a confirm message before cancelling the record. So I changed the script from

current.state = 10;
current.update();
action.setRedirectURL(current);

To:

function cancelRecord() {
    var st = g_form.getValue('state');
    g_form.setValue('state', 8);

    var answer = confirm('Are you sure you want to cancel this record?');
    if (answer != true) {
        g_form.setValue('state', st);
        return false;
    }
    gsftSubmit(null, g_form.getFormElement(), 'cancel');
}

if (typeof window == 'undefined')
    serverResolve();

function serverResolve() {
    current.state = '10';
    current.update();
    action.setRedirectURL(current);
}

I checked "True" to client check box & added the client function name to "onclick" field.

But the problem is, the client side is running, but the server side is not running. 

I am getting confirm box, but after click on this, the state is not changing to cancel, and page is not redirecting to same page.

 

Anyone please help me on this, what could be the peoblem!!!!!!!!

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@chandan15 

Are you sure in the Action name you entered "cancel"

why are you setting the state value in client side when you are already setting it in server side?

Update as this

function cancelRecord() {

	var answer = confirm('Are you sure you want to cancel this record?');
	if (answer != true)
		return false;
	else
		gsftSubmit(null, g_form.getFormElement(), 'cancel');
}

if (typeof window == 'undefined')
	serverResolve();

function serverResolve() {
	current.state = '10';
	current.update();
	action.setRedirectURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Can you change the action name and try.

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

View solution in original post

9 REPLIES 9

Can you change the action name and try.

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Awesome, good guess, the conflict was happening for action name.

Now it started working.

Thank you very much!!!!

Ankur Bawiskar
Tera Patron
Tera Patron

@chandan15 

Are you sure in the Action name you entered "cancel"

why are you setting the state value in client side when you are already setting it in server side?

Update as this

function cancelRecord() {

	var answer = confirm('Are you sure you want to cancel this record?');
	if (answer != true)
		return false;
	else
		gsftSubmit(null, g_form.getFormElement(), 'cancel');
}

if (typeof window == 'undefined')
	serverResolve();

function serverResolve() {
	current.state = '10';
	current.update();
	action.setRedirectURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur,

yeah, the action name is "cancel" & onclick as "cancelRecord();".

But something is wrong, the server side code is not running.

Once I click "ok" on confirm message, the page is refreshing, but the state is not changing.

ui action cancel.JPG

The reason I could not find.

Thank you !!!

@chandan15 

did the confirm box come?

 

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