UI Action redirect - portal vs. back-end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2022 11:43 AM
Our team is creating an UI Action on a form and would like it to redirect to another page on the portal, but redirect to another form on the back-end. Right now when a user submits a new user on sys_user in the back-end, the button will redirect them directly to the HR Profile form as a next step. When a user does this same action in the portal, we would like to redirect them to another portal page for the HR Profile form. Is there a way to script this?
current.update(); //updates the sys_user record
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if(profile)
action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2022 11:53 AM
Could you please provide the full script for your UI action? Is the button already displaying properly on the portal?
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2022 11:59 AM
Hi, that actually is the full script for the UI Action. Right now in the back-end it looks like this:
When clicked, it takes the user here:
All of that is working as expected in the back-end, but we want to do something similar in the portal. In the above script, is there a way to say if portal then redirect here else redirect there?
something like this...?
current.update(); //updates the sys_user record
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if(profile){
if(portal){
//redirect to this url
} else {
action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2022 12:50 PM
Got it -- I think the below should work:
current.update(); //updates the sys_user record
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if(profile){
var portal = gs.action.getGlideURI().toString().startsWith('api/now/sp'); //true if service portal, false if native view
if(portal){
//redirect to this url
} else {
action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));
}
}
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry