- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 08:59 AM
@Mark Roethof Thanks! Your below post helps me solving BR for the new Cases.
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 09:57 AM
@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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 10:25 PM
Hi,
Have you tried adding some logs?
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addEncodedQuery('table_nameLIKEsn_hr');
grAttachment.query();
gs.info('AAAAA Found Attachments : '+grAttachment.getRowCount());
while(grAttachment.next()) {
var grRecord = new GlideRecord(grAttachment.getValue('table_name'));
grRecord.addQuery('sys_id', grAttachment.getValue('table_sys_id'));
grRecord.addEncodedQuery('state=2');//<use different states values>
grRecord._query();
if (grRecord._next()) {
gs.info('AAAAA Updating Has Attachments on case : '+grAttachment.getRowCount());
grRecord.setWorkflow(false);
grRecord.u_has_attachment = true; //<custom column in sn_hr_case_core table>
grRecord.update();
}
}
See if these logs coming in, also try running this script in Application scope.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 09:57 AM
@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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 10:33 PM
Hello @Community Alums ,
There are some typo in your script
grRecord.query(); // Use 'query()' instead of '_query()'
if (grRecord.next()) { // Use 'next()' instead of '_next()'
Also you can try to change encoded query as below
// Make sure to replace 'sn_hr_case_core' with the actual table name of your HR cases table
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addEncodedQuery('table_name=sn_hr_case_core'); // Use '=' instead of 'LIKE' to match exact table name
grAttachment.query();
while (grAttachment.next()) {
var grRecord = new GlideRecord(grAttachment.getValue('table_name'));
grRecord.addQuery('sys_id', grAttachment.getValue('table_sys_id'));
grRecord.query();
if (grRecord.next()) {
grRecord.u_has_attachment = true;
grRecord.setWorkflow(false);
grRecord.update();
}
}
Kindly mark correct and helpful If applicable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 10:59 PM
FYI, _query() and _next() are alternative methods to query() and next().
Thanks
Anil Lande