How can we set attachment flag for existing HR Cases?

Community Alums
Not applicable

 

@Mark Roethof Thanks! Your below post helps me solving BR for the new Cases.

 

https://www.servicenow.com/community/hrsd-forum/how-to-check-if-hr-case-has-attachment/m-p/1336697/p...

 

For existing, Cases I am trying a Fix script by modifying the code but it not working. 

 

var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addEncodedQuery('table_nameLIKEsn_hr');
grAttachment.query();
while(grAttachment.next()) {
var grRecord = new GlideRecord(grAttachment.getValue('table_name'));
grRecord.addQuery('sys_id', grAttachment.getValue('table_sys_id'));
grRecord.addEncodedQuery('state=<different states>');
grRecord._query();
if (grRecord._next()) {
grRecord.setWorkflow(false);
grRecord.u_has_attachment = true; <custom column in sn_hr_case_core table>
grRecord.update();
}
}

I am running the Fix script in global scope.

Thoughts?

 

Thanks,

MK

1 ACCEPTED SOLUTION

Community Alums
Not applicable

@Anil Lande - I did add the gs.info() for testing prospective and it was going into the code too. Some how it was not executing the code.

I took a different approach, since I need to run the fix script for handful of records with the same HR Service and some specific states so I took the sys_id from attachment table and executed directly at the HR table level. In this way, I didn't face any RCA issue too. Moreover, in this way I know which records it is touching.

 

Here's the simplify code:

var grRecord = new GlideRecord('<HR workflow admin table>');
grRecord.addEncodedQuery('sys_idIN<bunch of sys_id>^state=10');
grRecord.query();
while(grRecord.next()) {
grRecord.setWorkflow(false);
grRecord.u_has_attachment = true;
grRecord.update();
}

View solution in original post

5 REPLIES 5

@Anil Lande , Thank you so much for letting me know. I was not aware about it.