Scheduled Job to close table records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 07:20 AM
Hi, I need to make scheduled jobs to close records for 2 tables.
I tried for 1st table with below codes, it works.
var transaction = new GlideRecord('x_shlt_shinsei_request_transaction');
transaction.addQuery('active', 'True');
transaction.addQuery('sub_state', 'waiting for approval');
transaction.addQuery('sys_created_on', '<=', gs.daysAgoStart(300));
transaction.query();
while(transaction.next()){
transaction.active = false;
transaction.comments = 'Test';
transaction.update();
}
Then I went the 2nt table, I made the code in similar logic but it doesn't work.
var transaction = new GlideRecord('x_shlt_shinsei_request_approval');
transaction.addQuery('request_number.state', 'IN' ,'Resubmitted,Submitting,requested,Return to Requestor');
transaction.addQuery('request_number.sub_state', 'waiting for approval');
transaction.addQuery('request_number.sys_created_on', '<=', gs.daysAgoStart(300));
transaction.query();
while(transaction.next()){
transaction.state = 'Cancelled';
transaction.update();
}
in addQuery, request_number is a reference type and state/sub_state/sys_create_on are columns in request_number.
for transaction.state = 'Cancelled';
state is a choice type with below choices.(in attachment 0313.PNG)
can anyone help me with this problem?
regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 12:44 AM
Hi @HaowenX
Have you tried to implement the same using flow designer?
Flow designer would be more straight forward when compared to Scheduled job.
Let me know if you need any help to configure the flow for this requirement.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 01:30 AM
Hi, thank you for replying me for this issue.
That's a good idea! I will try flow design and feed back to you later!
thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 05:55 AM
Just make sure that you set up the Run as file as System user in Flow designer.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 04:13 AM
Hi, @J Siva
I used a wrong application scope so flow couldn't change the records.
after I make the workflow in rignt scope, it works.
thank you so much!