- 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-13-2017 11:34 PM
the query i added in second line is it should not run for that status, code is working fine but it is taking time.
Thanks a lot Gaurav for your valuable support..
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.query();
while(gr.next())
{
var currentdate = new GlideDate();
var created_date = gr.getValue('opened_at');
var current_status = gr.getValue('u_choice_6');//Status
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)
{
gr.u_status_indicator = 3;
gr.update();
}
else if (currentdate >= ambercolorstate && currentdate <= ambercolorstate1)
{
gr.u_status_indicator = 2;
gr.update();
}
else if (currentdate > ambercolorstate )
{
gr.u_status_indicator = 1;
gr.update();
}
//}
//gs.log('status indicator is '+gr.u_status_indicator);
// Add your code here
}
===================
Thanks a lot Gaurav
- 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.