- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 09:45 AM
Hello Developer community,
I ran into an issue trying to set if conditions in a sc_cat_item_producer script. I have a redirect working to direct the submitter to the task record. I want to make a if and else if in the script. If the user has the contract admin role to be redirected to the task record and else if false to redirect to my thank you page. I believe my code is incorrect.
Thank you for Assistance
Script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 12:55 PM - edited 05-03-2024 12:59 PM
Simplest would be to use the gs.hasRole() method:
if (gs.hasRole("contract_admin"))){ //hasRole will return true if the current user has the specified Role
producer.portal_redirect = 'u_contract_master.do?sys_id=' + current.sys_id;
} else {
producer.portal_redirect = "/cca?id=cca_thankyou";
}
You don't actually specify where the userRoles variable is from or gets its data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 10:17 AM
Hey @Wyatt Fudal1,
Please take a look at the following script. I believe your use of 'indexOf' was incorrect. This should fix it.
Cheers,
Josh
If you found this helpful please give a thumbs up OR mark it as the solution. Thank you!
var hasContractAdminRole = userRoles.indexOf('contract_admin') !== -1; // should be true if the role is found
if(hasContractAdminRole) {
producer.portal_redirect = 'u_contract_master.do?sys_id=' + current.sys_id;
} else {
producer.portal_redirect = "/cca?id=cca_thankyou";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 12:55 PM - edited 05-03-2024 12:59 PM
Simplest would be to use the gs.hasRole() method:
if (gs.hasRole("contract_admin"))){ //hasRole will return true if the current user has the specified Role
producer.portal_redirect = 'u_contract_master.do?sys_id=' + current.sys_id;
} else {
producer.portal_redirect = "/cca?id=cca_thankyou";
}
You don't actually specify where the userRoles variable is from or gets its data.