importing user in sys_user table

ankit_gupta
Tera Contributor

i m importing user in sys_user table but i have to check condition about no duplicate records and also don't add user who don't have group

so where i have to write condition in script or in business rule when running transform map
and also wanna count of row that inserted successfully

4 REPLIES 4

Deepa Srivastav
Kilo Sage

Hi Ankit ,



Make a field like user name or id which is unique as coalesce field. This will prevent creation of duplicate record. In import and transform history (also in import progress bar shows that)   you can check the number of successful inserts/update/ignored.


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


sagaragarwal_
Kilo Explorer

Hi Ankit,



While importing data in serviceNow using Import sets, you can mark a field as unique. By marking a field unique, ServiceNow check that field value already exist or not in target table. (unique filed is called Coalesce Field)



If value does not exist then a new record is created against that value


if value exist, then fields of corresponding record are updated in case their is change in you imported data.



> You can mark any field Coalesce while creating a transform map or going to already created transform map


> when you open a transform map


> Look at the related list "Field Maps" you'll see a column with name "Coalesce"


> Change the value from false to true against whichever field you want to mark as unique.



NOTE: Out of Box transform map for user table "sys_user" has "email" field as coalesce


mazhar4
Giga Expert

Ankit,



You need to check for the users group membership in the sys_user_grmember. If found set the ignore=true, this will skip inserting the record where the user is member of any group. For duplicates just use coalesce on any unique field like email etc.



var gr = new GlideRecord("sys_user_grmember");


gr.addQuery("user.email",source.u_email);


gr.query();


if(gr.next())


{


gs.log(" record found");


ignore = true;


}