- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 06:37 AM
Hi All,
I have a business rule that creates 1 or more of records in a related table so far so good.
I need to redirect to the record list in the related table when all records have been created and I cannot get the redirect to work at all.
This is for Service Portal but doesn't work in the backend either.
(function executeRule(current, previous /*null when async*/) {
var catPerData = current.somedata.toString();
var PerData = catPerData.split(',');
for (var i = 0; i < PerData.length; i++){
var gr = new GlideRecord ('some_data');
gr.initialize();
gr.number = current.sys_id;
gr.some_data = PerData[i];
gr.name = gr.some_data.name;
gr.insert();
}
var url = gs.getProperty('glide.servlet.uri') + 'lpcx?id=lf&table=some_data&filter=number' + current.sys_id + '&view=sp';
action.SetRedirectURL(url);
// gs.setRedirect(url);
})(current, previous);
Has anyone got any idea on what might be the issue?
Thanks!
Solved! Go to Solution.
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 09:17 AM
Please mark my solution, if that works for you.
Chirag A
Servicenow Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 07:46 AM
Hi Jaspal,
I tried gs.action.setRedirectURL(url);
doesn't work either 😞
I added a button but cannot see it in the Service Portal only in the backend and when I click it it does not work either. I tried it with w3 school url.
Something strange just happened in Service Portal, I update the record again to trigger the BR and after BR I stayed on the form but I hit form reload and the w3 schools website loaded.
the current record url was in the adddress bar so not sure but is this giving you any other ideas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 08:50 AM
Hi Ellie,
gs.setRedirect('www.google.com'); actually takes to the <instance url>/www.google.com. So ideally you should provide string as url without the instance url stuff. so your code will be go like...
var url = '/lpcx?id=lf&table=some_data&filter=number' + current.sys_id + '&view=sp';
gs.setRedirect(url);
One more thing, somehow on my Dev org I am unable to make it working. It behaves as below.
On table record Insert Display, I wrote a BR to redirect to '/xyz'. On display of that records the BR gets executed, but it does not go to ../xyz. In fact on refreshing the page / reloading the page it goes to the ../xyz url.
Hope, I am able to explain the behavior here.
Chirag A
Servicenow Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 08:54 AM
Hi Chirag,
I have exactly the same situation on page reload the redirect address is displayed.
Do you know if we can send a form reload with the BR and if so do you know how?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 09:14 AM
Hi Ellie,
Looks like I found the solution.
Create a BR with below Code and a Client Script code as below. Both together works for me...
//BR
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.setRedirect('/xyz');
})(current, previous);
Client script UIType ALL, Type OnLoad
function onLoad() {
if (location.pathname.indexOf('xyz')==1){
//no reload needed
}else{
location.reload();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2020 09:17 AM
Hi Ellie,
Looks like this can be your solution.
Create a BR with below Code and a Client Script code as below. Both together works for me...
//BR
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.setRedirect('/xyz');
})(current, previous);
Client script UIType ALL, Type OnLoad
function onLoad() {
if (location.pathname.indexOf('xyz')==1){
//no reload needed
}else{
location.reload();
}
}
Please mark my solution, if that works for you.
Chirag A
Servicenow Dev
Hi Ellie,
Looks like this can be your solution.
Create a BR with below Code and a Client Script code as below. Both together works for me...
Client script UIType ALL, Type OnLoad