how to pass dynamic URL inside gs.setRedirect(URL)?

patSnow
Tera Contributor

Hi Team,

I wanted to pass dynamic URL in gs.setRedirect(URL). URL should contain dynamic instance URL, so it will not impact the functionality when code will be pushed to higher instances. I'm using gs.setRedirect(URL) inside script include. I tried using action.setRedirectURL(gr) but it's not refreshing the page and user are still able to modify some fields.

some code mentioned in script include: 

var change = new GlideRecord('change_request');
change.get('sys_id');
change.state = '4';
change.u_close_code = 'Change cancelled';
change.update();
action.setRedirectURL(change);OR  gs.setRedirect(URL)//here I wanted to redirect to same record. 

Please advice 

1 ACCEPTED SOLUTION

Namrata Khabale
Giga Guru

Hey patSnow,

Refer the thread, it might help you:

https://community.servicenow.com/community?id=community_question&sys_id=36797726dbb7bfcc23f4a345ca96...

 

Mark correct and helpful if it resolves your issue!!!

 

Best Regards,

Namrata.

 

 

View solution in original post

4 REPLIES 4

Dan Ellis
Kilo Sage

As you are using a Script Include, try using:

var urlOnStack = gs.getUrlOnStack();
response.sendRedirect(urlOnStack);

Thanks,
Dan

Krishna  Penaka
Tera Expert

try this,

gs.setReturn(current.getLink(true));

gs.setReturn(current.getLink());

gs.setRedirect(current.getLink(true));

gs.setRedirect(current.getLink());

 
 

Namrata Khabale
Giga Guru

Hey patSnow,

Refer the thread, it might help you:

https://community.servicenow.com/community?id=community_question&sys_id=36797726dbb7bfcc23f4a345ca96...

 

Mark correct and helpful if it resolves your issue!!!

 

Best Regards,

Namrata.

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@patSnow 

As per your script you are not using any hard-coded instance name in the script

I assume you are using this code in UI action. If yes then gs object won't work for redirection

you should use action object

Please let us know what is the exact scenario and what is not working

Regards
Ankur

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