I need to implement "Reopen" button on the request form.

Navyaa
Tera Expert

Hi All,

I have requirement, where I need to implement the "Reopen" button on the request form.

I have the below UI Action :

Form Button : True
Action name: reopen_request
Client : True

Show Update : True

Show Insert : True

Onclick : reopenRequest()

function reopenRequest(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('request_state', in_process);
g_form.setValue('state',1);


//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(),'reopen_request'); //MUST call the 'Action name' set in this UI Action
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();

function serverResolve(){
current.request_state = 'in_process';
current.state = '1';
current.update();
}

Please anyone can help on this !!

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can have it as server side code and don't require client side for this; remove the client checkbox and function name

serverResolve();

function serverResolve(){

// get all RITMs for this request and update them to open then mark request state as open

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('request', current.sys_id);

ritm.query();

while(ritm.next()){

ritm.state = '1';

ritm.update();

}

current.request_state = 'in_process';
current.state = '1';
current.update();


}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

18 REPLIES 18

Hi Ankur,

As per your script, when I click "Reopen" button in the request form, the RITM state is getting changed to 'Open' but the request is still in 'Closed Complete' state.

If I uncheck the Client script the UI action is not working.

Here is the code :

function reopenRequest(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields


g_form.setValue('state',1);


//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(),'reopen_request'); //MUST call the 'Action name' set in this UI Action
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();

function serverResolve(){
// get all RITMs for this request and update them to open then mark request state as open
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id);
ritm.query();
while(ritm.next()){
ritm.state = '1';
ritm.update();
}
current.request_state = 'in_process';
current.state = '1';
current.update();


}

Hi,

why you want to use client side for this?

for only using server side; uncheck the client checkbox and put below code which is completely server side and let me know

also state value on sc_request 1 means Open; did you check the choice value for state on sc_request table at your side?

updated code to stay on current page after performing all the actions

serverResolve();

function serverResolve(){

// get all RITMs for this request and update them to open then mark request state as open

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('request', current.sys_id);

ritm.query();

while(ritm.next()){

ritm.state = '1';

ritm.update();

}

current.request_state = 'in_process';
current.state = '1';
current.update();

action.setRedirectURL(current);
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

Hi Ankur,

As 'Ropen Request' is a form button, if client script is not checked then how we can call the action name 

Here is my total script, however the RITM state is getting changed but the request is still the same in Closed Complete.

Please help ! Where am I doing wrong

Client Script : True

onClick : reopenRequest()

Action name : reopen_request

function reopenRequest(){

// //Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
// //g_form.setValue('request_state',in_process);

g_form.setValue('state',1);


// //Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(),'reopen_request'); //MUST call the 'Action name' set in this UI Action
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();

function serverResolve(){
// get all RITMs for this request and update them to open then mark request state as open
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id);
ritm.query();
while(ritm.next()){
ritm.state = '1';
ritm.stage = 'fulfillment';
ritm.update();
}
current.request_state = 'in_process';
current.state = '1';
current.active = 'true';
current.update();
action.setRedirectURL(current);
}

Hi,

you are using client checkbox and setting the value using g_form.setValue();

again setting the value using server side using current object

Can you try this code; let me know what issue you are facing?

can you try to set state value as integer instead of string i.e. use

current.state = 1

serverResolve();

function serverResolve(){
// get all RITMs for this request and update them to open then mark request state as open
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id);
ritm.query();
while(ritm.next()){
ritm.state = '1';
ritm.stage = 'fulfillment';
ritm.update();
}
current.request_state = 'in_process';
current.state = 1;
current.active = true;
current.update();
action.setRedirectURL(current);
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi ,

But where you are using the Action Name . Can you explain it