- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:18 PM
Hi,
on Creation of a user in csm_consumer_user table i want to add of consumer to that user.
how can i script this in business rule
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:29 PM
Hi,
You can have after insert BR on csm_consumer_user table
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var roleRecord = new GlideRecord('sys_user_has_role');
roleRecord.initialize();
roleRecord.user = current.sys_id;
roleRecord.role = 'role sys_id here'; // give here the role sys_id
roleRecord.insert();
})(current, previous);
Regards
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:27 PM
Hi there,
Something like this should work (only change the roles!). You might also consider playing around with Flow Designer, with that you can achieve the same no code.
Business rule
Table csm_consumer_user
After (or Async)
Insert
+ Script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sys_user_has_role');
gr.initialize();
gr.setValue('user', current.getUniqueValue());
gr.setValue('role', 'sysid_of_the_other_role');
gr.insert();
})(current, previous);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:29 PM
Hi,
You can have after insert BR on csm_consumer_user table
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var roleRecord = new GlideRecord('sys_user_has_role');
roleRecord.initialize();
roleRecord.user = current.sys_id;
roleRecord.role = 'role sys_id here'; // give here the role sys_id
roleRecord.insert();
})(current, previous);
Regards
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 09:45 PM
Hi there,
Would you mind marking my answer as correct? Ankur is just posting almost the same what I already mentioned before.
Kind regards,
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 10:13 PM
Hi Mark,
Seems your post was edited later possibly with the script after I posted mine.
Regards
Ankur