Redirect users after submission according to user's role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 04:07 AM
Hi,
I have the widget 'SC Catalog Item Req2RITM'. I want to adjust it so after the user clicks submit when creating a new request, he will be redirect according to his role:
1. if the current login user has an 'itil' role, then he will be redirect to:
current_instance_url/now/sow/record/sc_req_item/current sys_id of the ritm
e.g: http://testtest/now/sow/record/sc_req_item/1bb4ca34e822311020d202197b700b30
2. if the current login user does not has itil role, he needs to be redirect to:
current_instance_url/esc?id=standard_ticket&is_new_order=true&table=sc_req_item¤t sys_id of ritm
e.g: http://testtest/esc?id=standard_ticket&is_new_order=true&table=sc_req_item&sys_id=878ffb41dc22311020...
Client script:
api.controller=function($scope , $location) {
/* widget controller */
var c = this;
//$sp.service_catalog.cart.submitted - .request_method
//$sp.sc_cat_item.submitted
//SC Catalog Item widget emits an event when a record is succesfully submitted
//Catch the server response and capture a redirect
$scope.$on("$sp.sc_cat_item.submitted", function($event , $data){
console.log($event);
console.log($data);
//Get Details on the RITM
if($data.hasOwnProperty('table') && $data.table === "sc_request"){
$scope.server.get({action: "get_record" , request_id : $data.sys_id}).then(function(response){
console.log(response.data);
//Only Redirect to ritm if
//Global redirect override is enabled
//Item is configured to redirect
if(!response.data.error && response.data.ritm_redirect == "true"){
$location.search("id=" + c.options.page_id +
"&is_new_order=true&table=" + response.data.table +
"&sys_id=" + response.data.ritm_id);
return;
} else {
$location.search('id=sc_request&is_new_order=true&table=sc_request&sys_id=' + $data.sys_id);
}
})
}
//Handle Record Producers
if($data.hasOwnProperty('redirect_portal_url') && $data.redirect_portal_url !== ''){
$location.url(data.redirect_portal_url);
return;
}
//Fallback to a record
$location.search("id=ticket&is_new_order=true&table=" + $data.table + "&sys_id=" + $data.sys_id);
})
};
Server Script:
(function() {
var catItemProps = {
"show_add_cart_button" : options.show_add_cart_button,
"auto_redirect" : "false"
}
data.catItemWidget = $sp.getWidget('widget-sc-cat-item-v2' , catItemProps);
data.systemProperties = {
"redirect_override" : gs.getProperty('x_295070_req2ritm.redirect_override' , 'false')
}
if(input && input.action == "get_record"){
var scReqItemGR = new GlideRecord('sc_req_item');
scReqItemGR.addQuery('request' , input.request_id);
scReqItemGR.query();
if(scReqItemGR.next() && scReqItemGR.getRowCount() == 1){
data.ritm_id = scReqItemGR.getUniqueValue();
data.table = scReqItemGR.getTableName();
data.ritm_redirect = data.systemProperties.redirect_override === 'false' ? scReqItemGR.cat_item.x_295070_req2ritm_redirect + '' : 'true';
data.error = false;
} else {
data.error = true;
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 11:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 11:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 03:43 AM
Hi @Alon Grod
May I know what is reason for different redirection? What value you will get from this.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 11:05 AM
@Dr Atul G- LNG this is the requirement