8 Replies Latest reply on Oct 17, 2017 10:47 AM by blwallace

    Notification calculation

    blwallace Apprentice

      Running 2017.1.

      I have a process where I need to notify my CSO if a temporary access card has been out for a given amount of time, essentially a past due card.  My calculation is below, but it doesn't work as expected.  It never sets the flag to True.

       

      import System
      static def GetAttributeValue(Request):
      Flag = 'False'
        if Request.Status.Name == 'Assigned':
          AssignedDate = Request.CreationDate
          TimeSinceAssigned = Request.GetBusinessTime(AssignedDate,DateTime.UtcNow)
          if TimeSinceAssigned.TotalHours > 10:
            if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
              Flag = 'True'
      return Flag
      

       

      When I run Test Calculation is get an error "Function not available at client"  I understand from this document, Troubleshooting calculation error messages, that this is normal behavior.  It appears that AssignedDate never gets set, therefore, TimeSinceAssigned never gets set and hence, my Flag never gets set to True.

       

      Hoping someone can help and/or suggest how to troubleshoot.

       

      Thanks,

       

      Bart

        • 1. Re: Notification calculation
          JulianWigman Expert

          The calculation looks good to me.

           

          You could perhaps dump the AssignedDate variable ond replace the one reference to it with the Request.CreationDate just to simplify things and remove one potential failure point. That said when can the Request creation date ever be not set!!!

           

          You are 100% the “name” attribute of the stus is correct?

           

          Does the process go direct to Assigned status on creation as this is what the assignment is suggesting?

           

          I‘m sure the calc can be made to test though.  I normally create a string field and put a copy of the calc on that for debugging if all else fails. Then at places in the process I concatenate variable values on a temp string i can return to see what the calc is seeing as it executes.

           

          All being equal though I cant see much wrong with the code listed.  I have had calcs in the past where getbusinesstime function has seemed a bit flaky and returned nothing.

           

          Julian

          @MarXtar

          • 2. Re: Notification calculation
            blwallace Apprentice

            I took your advice, and dropped AssignedDate.  Now, if I run this calculation...

             

            import System
            static def GetAttributeValue(Request):
            Flag = 'False'
            if Request.Status.Name == 'Assigned':
            # TimeSinceAssigned = Request.GetBusinessTime(Request.CreationDate,DateTime.UtcNow)
            # if TimeSinceAssigned.TotalHours > 10:
            # if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
            Flag = 'True'
            return Flag
            

             

            ...it returns "True" for all Assigned Requests.  Assigned here is not a process assignment, but a status I'm using.  I'm assigning a temporary access card to a person, hence the status Assigned.

             

            If I can't test TimeSinceAssigned in the console, how best to troubleshoot this variable?  I don't understand your "I‘m sure the calc can be made to test though.  I normally create a string field and put a copy of the calc on that for debugging if all else fails. Then at places in the process I concatenate variable values on a temp string i can return to see what the calc is seeing as it executes."

            • 3. Re: Notification calculation
              blwallace Apprentice

              Maybe I understand your debugging technique.  I created a test_calc string attribute on Request, then added that to my request window.  I can now see the return value.  So this code...

              import System
              static def GetAttributeValue(Request):
              Flag = 'False'
              if Request.Status.Name == 'Assigned':
              # TimeSinceAssigned = Request.GetBusinessTime(Request.CreationDate,DateTime.UtcNow)
              # if TimeSinceAssigned.TotalHours > 10:
              # if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
              Flag = 'True'
              return Flag
              

              ...now shows True as I assign a card to a user and the status moves to Assigned.

               

              Next, I tried to set Flag = TimeSinceAssigned and remove the comment on line #5...

              import System
              static def GetAttributeValue(Request):
              Flag = 'False'
              if Request.Status.Name == 'Assigned':
              TimeSinceAssigned = Request.GetBusinessTime(Request.CreationDate,DateTime.UtcNow)
              # if TimeSinceAssigned.TotalHours > 10:
              # if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
              Flag = TimeSinceAssigned 
              return Flag
              

              ...but nothing is returned when my status is Assigned.

              • 4. Re: Notification calculation
                JulianWigman Expert

                This maybe because TimeSinceAssigned is a Timespan object so maybe it doesn't like returning that,  so maybe try  TimeSinceAssigned.TotalHours.

                 

                My potential "suspect" here is the GetBusinessTime function as I've had scenarios where this has unexpectedly returned null in the past as well. 

                 

                You can turn on diagnostics for calculation property in ConfigurationCenter and see if that yields any further info.

                 

                If it were me the next step would be to rule out that function.  So for the purposes of the test just assume for the moment we calculate the full elapse time between CreationDate and Now instead of the SupportHours so substitute the line with (just to test theory).

                 

                TimeSinceAssigned = DateTime.UtcNow - Request.CreationDate

                 

                If this works with the rest of your calculation unchanged you know where to point the finger and raise a Support case with Ivanti if as I suspect.

                 

                The tags suggest you are on Service Desk 2017.x, right?

                 

                Julian

                @MarXtar

                • 5. Re: Notification calculation
                  blwallace Apprentice

                  Julian,

                   

                  Thanks for the debugging tip.  I put in your suggestion of TimeSinceAssigned = DateTime.UtcNow - Request.CreationDate and that works.

                   

                  When looking at the documentation for GetBusinessTime function, I see several references to SLA and calendars.  I'm currently looking into those areas for a Request.  I have a business calendar already established and it appears I have priorities for Request's, but since the documentation is rather vague (it just mentions GetBusinessTime is tied to calendars and sla's), I'm not sure if this is the problem with GetBusinessTime.

                  • 6. Re: Notification calculation
                    blwallace Apprentice

                    I have my calculation working.

                    import System
                    static def GetAttributeValue(Request):
                    Flag = 'False'
                      if Request.Status.Name == 'Assigned':
                        TimeSinceAssigned = Request.GetBusinessTime(Request.Lifecycle.LastUpdate , DateTime.UtcNow)
                        if TimeSinceAssigned.TotalHours > 24:
                          if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
                            Flag = 'True'
                    return Flag
                    

                     

                    Per the documentation...

                    GetBusinessTime( DateTime1 , DateTime2 ) – returns the number of business hours between two date/time values based on the calendar associated with the response level for the process.

                     

                    My Request response level was set to the Default calendar.  Once I set response levels to my business calendar, my calculation started functioning properly.

                    • 7. Re: Notification calculation
                      JulianWigman Expert

                      Hmm that’s interesting and glad that fixed.

                       

                      Strange the default calendar didnt work as well though as it is still a calendar! How does the default one differ from the “Business” one also created; support hours, holidays etc.  Maybe somthing in the default calendar it doesnt like or maybe as you say the function just doesnt like it because it is set default and thus a possible bug.  You could prove the latter by temporarily setting your business calendar as default and see if it breaks. 

                       

                      Always bugs me if I don’t fully get to the bottom of a root cause!  

                       

                      Julian

                      @MarXtar

                      1 of 1 people found this helpful
                      • 8. Re: Notification calculation
                        blwallace Apprentice

                        I get the bottom of the root cause thing.  Since I hadn't done anything with Requests before, there was not need to set up Response Levels.  When I eventually looked into that side of things, the field had Default in it but not sure if that was ever set.  Kind of like the notification check boxes that have to be checked then unchecked before saving a notification action window - maybe?  Anyway, I set my business calendar and GetBusinessTime started working. 

                         

                        -btw My default calendar is set for Dublin, Edinburgh - so maybe I didn't wait long enough.  I'm in central time zone.  :-)

                        1 of 1 people found this helpful