5 Replies · Latest reply on Dec 5, 2017 8:18 AM by Adam Stout

    Business Rule or ? for field update

      Good morning community,

       

      My change control team is asking me to create some reports/dashboards to simplify their lives, and I had a question. They are wanting a new field created, called STATUS, that is dependent upon the current date, the start date, and the end date. If before, between, after kind of thing, change the value of this STATUS field.

       

      Since we are not looking into the records themselves (though we are querying the table to pull those changes with the dates we are looking for), what is the best way to have this new field populated with the correct value, at the time the list is generated?

       

      Business rule? I have not done something quite so independent of the form, so it did not feel correct, but I don't have a better idea. This value would change when the start time became the NOW, and again once past the scheduled END, etc. Seems like having it run every time the table is queried, might cause some delay or performance problem.

       

      Thanks for any tips!

      Jeff

        • Re: Business Rule or ? for field update
          Sachin Namjoshi

          You can create business rule to achieve this requirement.

          You can compare current time stamp with current, future start date in business rule condition and then update STATUS field value as per your business logic.

           

          You need to figure when this business rule need to be triggered.

           

          Regards,

          Sachin

          Please mark answer as Correct, helpful as appropriate.

          • Re: Business Rule or ? for field update
            Josh Cooper

            If this is a thing that you want to update each time you open a list view of those reports, then an onQuery Business Rule is probably the way to go.  It does have some load, but that's a pretty light script, so shouldn't be too bad as long as you limit it to only performing the evaluations against active changes... ideally changes within a particular state or two, the smaller the subset the better.

             

            If it's fine to know daily, then you can do this with a PA Bucket Group and Breakdown script.  It's an unconventional use but the way it works would be something like this:

             

            Create Bucket Groups for the statuses, such as:

             

            Pending  -   From 0   To   1

            Active - From  1   to  2

            Overdue - From  2  to  3

             

            Then, create your breakdown as you would normally for a pa_bucket type breakdown.


            In the breakdown script, create a function and just return the corresponding value based on the values (these aren't the right variable names, but you should hopefully get the idea):

             

            getVal();

             

            function getVal(){

                 var now = nowDateTime();

                 if (now < current.start_time){

                      return '0';

                 } else if (now > current.start_time && now < current.end_time){

                      return '1';

                 } else {

                      return '2';
                 }

             

             

            }

             

             

            Even though buckets were intended to be used for ranges, the way it works you should be able to use it for a conditional evaluation as well.  Plus, because it's PA, it doesn't require change control to implement, doesn't require an admin to create a new field, or a new business rule, and any impact is only when it runs the PA Job.

            1 of 1 people found this helpful
            • Re: Business Rule or ? for field update
              Adam Stout

              What about using a calculated field?  There are some issues with querying based on this field, but it can be very useful and simple to implement if it is just for display.