Bulk update using oncomplete transform script

Sangeeta9
Tera Contributor

Hi All,

 

I am trying to deactivate the records which are not part of the import set.

There are around 3 lakh records in the system  for which the queries runs. The import is getting stuck due to this oncomplete transform script. If we deactivate the oncomplete script the import gets completed with no issues.

 

Is the mass update causing the issues. Below is the script

 var acc;
    var ent= new GlideRecord('x_syslt_iam_m2m2ibeam_project_community_identity_relationships');
    ent.addEncodedQuery('u_active=true');
    ent.query();
    while (ent.next()) {
 
        acc= new GlideRecord('x_syslt_iam_iam_ibeam_accounts_import');
        acc.addEncodedQuery('sys_import_set=' + source.sys_import_set + '^u_accountname=' + ent.u_account.user_id.toString() + '^u_entitlementvalue=' + ent.u_project_community_combo.u_display_name.toString());
        acc.query();
        if (acc.hasNext() == false) {
            ent.setWorkflow(false);
            ent.u_active = false;
            ent.update();
            ent.setWorkflow(true);
        }
    }

 

1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Sangeeta9 ,

 

Can you try to write down Script Action and call it from your Oncomplete transform script. As the script actions runs asynchronously so it might not impact on the instance.

You can triggered event from OnComplete script and also pass the parameters of source fields in form of array and then use them in your encoded query.

reference for it : How can we access event parm1 & parm2 values in script action? 

Just a sample code : Replace that source fields with array variable.

GunjanKiratkar_0-1688538265872.png

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

3 REPLIES 3

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Sangeeta9 ,

 

Can you try to write down Script Action and call it from your Oncomplete transform script. As the script actions runs asynchronously so it might not impact on the instance.

You can triggered event from OnComplete script and also pass the parameters of source fields in form of array and then use them in your encoded query.

reference for it : How can we access event parm1 & parm2 values in script action? 

Just a sample code : Replace that source fields with array variable.

GunjanKiratkar_0-1688538265872.png

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Weird
Mega Sage

How about just removing parts and seeing if that helps? I don't see anything majorly bad that could break it, but you could try slimming the code a bit.

Here's a few tweaks. source.sys_import_set should work, but at the same time onComplete script should have access to that with "import_set" value.
Also make sure to read through the table names and field names to make sure they're correct. For example "u_entitlementvalue" is one where I'd expect it to be "u_entitlement_value".

Also make sure to log some values and then check the logs whether you're getting information you'd expect.
For example what if the u_display_name is empty? Should you have a failsafe for those kind of situations?

var ent = new GlideRecord('x_syslt_iam_m2m2ibeam_project_community_identity_relationships');
ent.addEncodedQuery('u_active=true');
ent.query();
gs.info("Identity relationships found: " + ent.getRowCount());
while (ent.next()) {
    var account = ent.u_account.user_id.toString();
    var entitlement = ent.u_project_community_combo.u_display_name.toString();
    gs.info("Entitlement and account: " + entitlement + " " + account);
    var acc = new GlideRecord('x_syslt_iam_iam_ibeam_accounts_import'); //Is the table iam_iam?
        acc.addEncodedQuery('sys_import_set=' + import_set + '^u_accountname=' + account + '^u_entitlementvalue=' + entitlement);
        acc.query();
        gs.info("Accounts found: " + acc.getRowCount());
        if (!acc.hasNext()) {
            ent.setWorkflow(false);
            ent.u_active = false;
            ent.update();
        }
}

 
You could also consider adding a Date field to your target table. Then on your transform you can set target.u_last_checked (the date field) to gs.now(), which would be today's date.
If your transform doesn't update the date then you know that any records not updated today are to be set inactive.

OlaN
Giga Sage
Giga Sage

Hi,

Another way to do this, is to set the import date on the records that are in the import set.

Then after the import is complete, you can in an oncomplete transform script disable all records, that does not have the latest import date set.