Records not getting updated in List View

Reddymahesh
Tera Contributor

Currently , I have worked on a development where if service owner or service owner group has been changed on mapped application service table, It needs to be automatically updated in all the related incidents.

Issue is like only few records were seen getting updated on table list view not all.

 

Thanks. Below is the code for the BR I have used

 

(function executeRule(current, previous /*null when async*/ ) {
 
    var gr = new GlideRecord('incident');
    gr.addQuery('cmdb_ci', current.sys_id);
    gr.query();
    while (gr.next()) {
        gr.u_service_owner = current.managed_by;
        gr.u_service_owner_group = current.u_service_owner_group;
gr.update();
    }
 
})(current, previous);
21 REPLIES 21

sushantmalsure
Mega Sage
Mega Sage

can you check the incidents where Service Owner and Service Owner Group not updated have same cmdb_ci / sys_id of record, from where this business rule is getting triggered?

 

I would suggest run following in background script to know how many incidents have application service as cmdb_ci:

 

var applicationID = '<add sys_id of application service>'; // add sys_id of application service here 
var gr = new GlideRecord('incident');
    gr.addQuery('cmdb_ci',applicationID);
    gr.query();
while(gr.next()){
gs.print('Incident '+gr.number);
}

By this way you will get which are the incidents have the application service under configuration item of incident and then proceed further.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

I have run in background script to verify using getRowCount and it is matching the exact number of records which I will get from list of records after applying filter condition

that means query is correct.

Try following script in business rule and check again

 

 

 var grUpdate = new GlideRecord('incident');
    grUpdate.addQuery('cmdb_ci', current.sys_id);
    grUpdate.query();
    while (grUpdate.next()) {
        grUpdate.u_service_owner = current.managed_by;
        grUpdate.u_service_owner_group = current.u_service_owner_group;
		grUpdate.setWorkflow(false);  // I have just added this to make sure there are no aftereffects like running incident update actions
grUpdate.update();
    }

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Reddymahesh
Tera Contributor

@sushantmalsure  As we are using setWorkflow(false) here, business rule which updates the journal fields is not getting triggered because of which it is effecting audit of the incident table. We are not able to see update in activity and not able to see anything in history of the record.

Basically when you use setWorkflow(false) it works then there must be some more BR which are running before this update which is stopping the execution.

I  suggest turn on the business rule debugger and then run the script, to follow execution of all BR and check where exactly its stopping the update.

Our hands are tied here because we can not see the complete BR configurations on your instance, as the script shared for update looks good.

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure