- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2020 07:27 PM
Hi All,
I need help to create a scheduled job to update state field on task table as per the Request state field on Sc_request table.
Suppose if the Request state on Request table is closed complete then update the State field on task to closed completed too.
Scheduled job is to check what all request are not updated correctly and update them.
For instance : we have few Requests records with "Request state" as closed complete but the state field on task table remain "Pending", those request records need to be updated
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2020 06:00 AM
1) Before Business Rule
2) Set the conditions as per your query i.e state = -5 and request state is completed in condition builder of business rule
3) Try the below script, update as per requirement.
var app=new GlideRecord('YOURTASKTABLENAME');
app.addQuery('number',current.number);
app.query();
if(app.next())
{
//Make use of setWorkflow false if required.
app.state = '3';
app.update();
}
}
Hope this helps!
Please Mark as ✅ Correct if this solves your issue and also mark (y) Helpful if it helps resolve your problem.
Thanks,
Saji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2020 08:42 PM
Is there a reason you're wanting to use a scheduled job? I'm assuming this occurred due to some error that has since been corrected (this happened to us before too). The better solution in my opinion would be to create business rule(s) to run on close of the record to keep things in sync. Then perform a 1 time cleanup to fix those that are currently incorrect.
If my reply has helped in any way, kindly mark it correct/helpful. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2020 11:09 PM
Yes, our final solution is to create Business Rule and scheduled job will be one time clean-up.
Can you share the business rule and Background script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2020 10:31 PM
Please share your script here for assitance, and maybe make use of Business rule instead of Scheduled Jobs.
Thanks,
Saji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2020 11:12 PM
We are planning to create Business Rule but for the one time clean-up we need Background script/scheduled job.
Background script worked as expected.
var app=new GlideRecord('sc_request');
app.addQuery('state','-5');
app.addQuery('request_state','closed_complete');
app.setLimit(2);
app.query();
while(app.next())
{
gs.print('total '+app.getRowCount());
gs.print(app.number);
if (app.request_state == "closed_complete") {
app.state = '3';
app.update();
}
}
Need Help with a Business Rule now.
Thanks!