- 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-11-2017 01:54 AM
Hi Suryan,
I don't think you can use BR alone for this requirement as you cant change DOM values the from server side.
Please try with an Onload Clientscriptt with a display BR where you can set the set some parameter through scratchpad and then manipulate DOM in clien script.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 01:59 AM
so i need to write a client script for this. how to set parameter through scratchpad and display BR in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 02:10 AM
You can set the value in a variable, let say your ticket has not been updated from 5 days.
So in your code,
if (currentdate >= redcolorstate)
{
//current.u_status_indicator = 3;
//gs.addInfoMessage(current.u_status_indicator);
//current.update();
g_scratchpad.redColor ="true";// set the redColor varibale to true and pass it in sctreachpad.
}
Now in OnLoad Client Script,
if(g_scratchpad.redColor == "true") {
//do DOM maniplaution,
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2017 02:33 AM
in client script i wrote the below code it is throwing error as "The object "current" should not be used in client scripts."
if(g_scratchpad.redColor == "true")
{
current.u_status_indicator = 3;
}
else if (g_scratchpad.greenColor == "true") {
current.u_status_indicator = 3;
}
else if (g_scratchpad.amberColor == "true") {
current.u_status_indicator = 3;
}