We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Onbefore Script for transform map

Rajitha Sunkara
Tera Contributor

Only group members who have an active user record in sys_user table should be added to the group when the transform runs.

Group members should only be added to an active group in the sys_user_group table.

So columns should be mapped as SOEID as user.user_name and group name as group_name.

So for we need onbefore scripting we have created that scripting but it is showing inactive users also.

The script is in the attachment.

Source Field: u_group_name

Target Field Mapping: group.name

Target Table:sys_user_grmember.

1 ACCEPTED SOLUTION

PavanK960672992
Mega Patron

Hi,

You can try this script:

on Sys_user table first you will check whether user is active or not

var grusr = new GlideRecord("sys_user");
grusr.addActiveQuery();
grusr.addQuery("user_name", source.SOEID ); // i am assuming soeid is source user field
grusr.query();
if(grusr.next()){ //if user is active then go to the sys_user_grmember table add user to that group

 var grusrmbr = new GlideRecord("sys_user_grmember");
                grusrmbr.addQuery("group.name", u_group_name); //u_group_name is source grup name
                grusrmbr.query();
                if (grusrmbr.next()) {
                    target.user = source.SOEID;
                } else {
                    target.user = '';

                }
    
}

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

5 REPLIES 5

PavanK960672992
Mega Patron

Hi @Rajitha Sunkara 

 

If your issue got resolved please close the thread by Marking Correct. So that others can benefit.

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar