Transform Script to ignore inactive record but update active record

tricial
Giga Contributor

I need help with the below use case:

I have to cleanup user records, there are duplicates but no general uniqiue identifier except the full name

I have tried a number of onbefore transforms and cannot get the active record to be updated

It ignores the inactive record fine, but it does not continue to find the active record and update that;

So I have a user

Full name:   James Brown

Multiple user_ids

Multiple email addresses (not always)

If I add this to the OnBefore Script

// if(!target.active){

// ignore = true;

// }

It finds the first record and if its inactive it does ignore it, however I need it to find all instances of this record and update the active one.

I tried this to see if I can lookup the users full name and if it finds the user inactive ignore it, if it finds it active update it.

Still not working.

Unfortunately the data in the sys_user table has duplicates that I am struggling with getting to update the correct record.

Since there are 90+k users (both active and inactive) I cannot easily clean this up until I have been able to update the active record.

I have a field that I am setting a value on after the record is updated that will allow me to cleanup all records that do not have this field value set, but in the meantime, I need help getting the active record updated.

var gr = new GlideRecord('sys_user');

gr.addQuery('name='+source.u_full_name.toString());

gr.query();

while(gr.next()){

if(!gr.addActiveQuery()){

ignore=true;

}

else{

target = gr;

}

}

// if(!target.active){

// ignore = true;

// }

Thank you

Tricia

1 ACCEPTED SOLUTION

One more option would be .. to include active in the transform map and coalesce on it, but this needs the source data to have active field on it and it should be set to true, this will ensure that only active records are picked up and updated and rest of the ones are ignored. I just tried and it worked. I have updated the country code for a user record which was United kindom earlier to Brazil.. Below are screenshots



Import spreadsheet


find_real_file.png



Transform Map



find_real_file.png



Before Data load screenshot


find_real_file.png



find_real_file.png


After Data load and transform -screenshot



find_real_file.png



Hope this helps !



Thanks
Anil


View solution in original post

11 REPLIES 11

Govind1
Kilo Contributor

Hello Anil and Patricia,

 

I have similar case but I am unable to ignore the records for which active == false in the source table. I am able to update the active records also I can set the active records to false but can't stop creating new records even though the source values of active is false.

We have a business rule where we add "DONOTUSE" prefix to the email and login ID of the records which are made inactive, this rule updates as soon as the records are updated to inactive status.

 

I have below onBefore script where I am checking whether the the email in the source has same or email ID with DONOTUSE prefix in user table, if yes then it will check whether active == false in the source and target table.   if yes then it should ignore it else it should update(this will be the case where target will true and source will be false)

 

if (source.u_email != "")
{
gs.log("Govind - after 1st if clause of source.email is not null," + source.u_email + "," + source.u_active );


var newemail = "DONOTUSE"+ source.u_email;


gs.log("source email," + source.u_email + "," + "and newemail value,"+ newemail);


var NewUser= new GlideRecord('sys_user');


NewUser.addQuery('email', source.u_email).addOrCondition('email', newemail);


gs.log("Govind - found user email" + source.u_email + "or" + newemail);


NewUser.query();


if (NewUser.next()) {


gs.log("Govind - Found new user" + "," + NewUser.next());


if (target.active == "false") {
gs.log("Govind - Is Active" + target.active);


ignore = true;

gs.log("Govind - target record ignored" + target.active);

} else ignore = false;
gs.log("Govind - else condition executed");
}
}