- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 04:00 AM
Hello Team,
I'm trying to import group members to sys_user_grmember table through transform map but here I want to assign roles to group using transform script but it's not working can anyone help me how to assign roles.
OnAfter
gr.initialize();
gr.user = getUserSysId(source.u_email_id); //based on email Id
gr.role = '282bf1fac6112285017366cb5f867469';
gr.insert();
{
var userGr = new GlideRecord('sys_user');
userGr.addQuery('email', emailId);
userGr.query();
if(userGr.next())
{
return userGr.sys_id;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:10 AM
Hi,
then why not give role to group in onAfter transform script instead of members
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 04:05 AM
Always assign role to group. Never assign role directly to user. Add users to a group and then assign the role.
In case your requirement is to assign role to multiple group kindly consider the below script.
For this you need to use the Background script.
Please activate your elevated privilege (i.e., the 'security_admin' role)-->Navigate to System Definition--> Scripts - Background-->and use the below sample code as per your requirement.
var gr = new GlideRecord('sys_group_has_role');
gr.addEncodedQuery('group.nameLIKEcatalog'); //It fetches all the group which contains 'catalog' in it's name. Please use your requiremnent.
gr.query();
while(gr.next()){
gr.role = '282bf1fac6112285017366cb5f867469'; //Pass the sys_id of the role which you want to add
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 04:13 AM
Hi Dhruv,
I have inserted groups in different data source and now loading group members based on groups and I know that we have assign roles to groups not to user that's why I was trying to write Transform Script On After which can assign roles to groups. I have tried your script but didn't worked.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 04:19 AM
Hi Chaitanya,
So where you want to give role
you have 1 data source which loads groups
you have 1 data source which loads group members
where have you written the transform map onAfter? is it for data source of group or members
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 04:51 AM
Hi Ankur,
I need to give roles on Group member transform map scripts.
Thanks,
Chaitanya