Need code in styles for the business rule.

suryan
Kilo Expert

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);

1 ACCEPTED SOLUTION

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.


View solution in original post

26 REPLIES 26

since it is case records table it is going to increase.



gr.addQuery('');


removing the above line(only one line) is that enough ?


Yes, certainly.


i disable that business rule and created the above scheduled job, it is not showing any value in that status indicator field


Did you execute it?


Please click on execute now button.


Also, put some logs to verify the process.



find_real_file.png


i click execute button and checked the status indicator, it is not showing any value