Transaction cancelled - Available memory is almost depleted - in background script

Community Alums
Not applicable

I have added setLimit also but getting Transaction cancelled - Available memory is almost depleted , please suggest, after query my total records are 28k and childgroup length is approx 26k, but when i checked in baground script its giving error.

Note: it is working fine if I add setLimit(1k)

 

var gr = new GlideRecord('cmdb_rel_ci');
gr.addEncodedQuery('child.category=Hardware^parent.install_statusNOT IN111,14^child.install_statusNOT IN111,14');
gr.setLimit(10000);
gr.query();
gr.query();
var childGroup = {}; // Object to store child records and their parent details
while (gr.next()) {
    var childSysId = gr.child.sys_id.toString();
    var parentDisplayValue = gr.parent.getDisplayValue();
    var parentOwnedBy = gr.parent.owned_by;
    var childOwnedBy = gr.child.owned_by.getDisplayValue();
    var childCorrelationId = gr.child.correlation_id;
    if (!childGroup[childSysId]) {
        childGroup[childSysId] = {
           parentOwnedBy: parentOwnedBy,
           childCorrelationId: childCorrelationId,
           childOwnedBy: childOwnedBy
        };
    }
}

gs.info("childGroup Length123: " + Object.keys(childGroup).length);

 

 

1 ACCEPTED SOLUTION

Hi @Community Alums ,

 

Yes, you can use scheduled job or script action both will work fine. make sure to use the setlimit() function to create batches for your script.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.


Thanks

Suraj

View solution in original post

3 REPLIES 3

surajchacherkar
Mega Guru

Hi ,

 

instead of using it in background script try to run it in scheduled job.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks

Suraj

Community Alums
Not applicable

Hi @surajchacherkar,

 

I am new to the ServiceNow, will scheduled job handle large ammount of data.

 

Thanks!

Hi @Community Alums ,

 

Yes, you can use scheduled job or script action both will work fine. make sure to use the setlimit() function to create batches for your script.

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.


Thanks

Suraj