- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 01:48 AM
I wrote a business rule to update status indicator with color green if created date is less than 3 days, amber if it is equal to or greater than 4 days and red if it is equal to 5 or more than 5 days. Status indicator field updates only when insert or update action is performed since it is business rule. I need the code to write this in styles.
Below is the business Rule written, how to apply it in STYLES?
(function executeRule(current, previous /*null when async*/)
{
var currentdate = new GlideDate();
var created_date = current.getValue('opened_at');
var redcolorstate = new GlideDate();
redcolorstate.setValue(created_date);
redcolorstate.addDaysLocalTime(5);
var ambercolorstate1 = new GlideDate();
ambercolorstate1.setValue(created_date);
ambercolorstate1.addDaysLocalTime(4);
var ambercolorstate = new GlideDate();
ambercolorstate.setValue(created_date);
ambercolorstate.addDaysLocalTime(3);
if (currentdate >= redcolorstate)
{
current.u_status_indicator = 3;
gs.addInfoMessage(current.u_status_indicator);
current.update();
}
else if (currentdate >= ambercolorstate && currentdate <= ambercolorstate1)
{
current.u_status_indicator = 2;
gs.addInfoMessage(current.u_status_indicator);
current.update();
}
else
{
current.u_status_indicator = 1;
gs.addInfoMessage(current.u_status_indicator);
current.update();
}
// Add your code here
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Enterprise Asset Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 11:50 PM
Hi Suryan,
Happy to help
Try with the limit of only 10 records and check.
Also, try the same script in background script and check whether its takes the same time or not?
var gr = new GlideRecord('sn_customerservice_case');
gr.addQuery('u_choice_6NOT IN4 - Ready for ISG testing,5a - ISG test successful,5b - ISG test failed,6 - Pushed to Production,7 - Closed,8 - Information Mail,91 - Rejected by Demand Board,92 - Cancelled by user');
gr.setLimit(10);
gr.query();
and before update set workflow false as well to stop any BR running after the script.
gr.setWorkfFlow(false);
gr.update();
You need to see whats causing the harm. Try different runs and see the output.
Should not be much of a hassle.
Thanks
Gaurav
PS: Mark the answer Correct. helpful based on the impact. This will help others to follow the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 02:54 AM
As I mentioned, please add logs in the script and then see till what point script is running.
Also, remove the gs.addInfoMessage(gr.u_status_indicator); and add gs.log('status indicator is '+gr.u_status_indicator).
Its only a matter of debugging now, verify errors, script log statements once you have placed the logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 09:32 PM
added the above log in scheduled job before while statement it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 11:19 PM
You will have to debug more to dins the root cause.
Scheduled Job is the solution you are looking for.
For once, try adding addQuery method for only one of the record and try the same script.
This way, you can refer the same record once script has run.
Otherwise, you can try the script for one record in background script as well.
Its all about your debugging skills now.
Let me know for any help.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 10:24 PM
Hi Gaurav,
I checked after running the schedule job and assume it is not working, now i came to know that it is taking 10 minutes to update just 20 records, totally i have around 800 records. Can u guide me why it is taking that much time and cant be reduced.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 11:06 PM
Hi,
Ideally it should not take this longer, can you check the logs when the job is starting.
You can try updating a single record and see how long does it takes.
Also, please share your script here so that i can take a look.