Scheduled Job to close table records

HaowenX
Tera Contributor

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!

7 REPLIES 7

J Siva
Tera Sage

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

HaowenX
Tera Contributor

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!

Just make sure that you set up the Run as file as System user in Flow designer.
Regards,
Siva

HaowenX
Tera Contributor

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!