- 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:10 AM
Hi,
Is it inserting empty row in that table?
Did you check by adding logs you are getting user sys_id
Also it is best practice to give role to group rather than user in this case.
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:16 AM
Hi Ankur,
There are only two fields on excel sheet which are Group & User which is same as on target table sys_user_grmember. I have tried to add user's are creating and they are assigned to specific group as well but roles are not getting assigned I need to assigned roles once group members are added to groups.
Thanks
Chaitanya
- 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 05:20 AM
Hi Ankur, thanks for suggestion I have tried below script on group transform map. it worked
groupsysid.get('name',source.u_name);
var gr = new GlideRecord('sys_group_has_role');
gr.addQuery('group',groupsysid.sys_id);
gr.addQuery('role','282bf1fac6112285017366cb5f867469');
gr.query();
if(!gr.hasNext()){
gr.initialize();
gr.group=groupsysid.sys_id;
gr.role='282bf1fac6112285017366cb5f867469';
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:22 AM
You are welcome
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader