4 Replies Latest reply on Mar 1, 2018 10:51 AM by rmastenbrook

    Calculation for DateTime Field from Incident to Problem

    rmastenbrook Rookie

      In my Incident workflow, I have a 'Create Problem from Incident' action, and then an automatic action to create a problem, with certain fields being populated from attributes within the Incident.

      Everything is working for the text fields using value types, but I am having some difficulty populating a DateTime from another DateTime.

       

      This is my current calculation:

      import System

      static def GetAttributeValue(Problem):

           Value = Problem.IncidentProblems.Incident._INTimeOfRestoration

           return Value

       

      That gives the error: "'Touchpaper.Framework.Data.DataObjectListProxy.Incident' not found"

      But all my text values I am able to pull from the Problem.IncidentProblems.Incident collection.

        • 1. Re: Calculation for DateTime Field from Incident to Problem
          Julian Wigman ITSMMVPGroup

          The reason is that IncidentProblems object is a many-to-many relationship. Alsi when you use a value type it always assumes the latest value which is selected implicitly.  Calculations dont work the same way and you must explicitly get the latest value; that is easy for one-to many objects (ie notes, resolutions etc) as you can use the latest() function to get it but for many-to-many (IncidentProblems) this isnt possible.  The “..DataobjectListProxy...” type error is the give-away.

           

          Instead here you need to get the latest value by looping around the IncidentProblems Object.

           

          You’ll find examples of how to do this on the community, and yiu just need to get the latest creation date.

           

          I’ll dig out an example and post a link.

           

          Julian

          MarXtar Ltd

          • 2. Re: Calculation for DateTime Field from Incident to Problem
            Julian Wigman ITSMMVPGroup

            Try something like (from memory)

             

            TestDate = null

            LatestObj = null

            for IncidentObj in Problem.IncidentProblems:

                 if (IncidentObj._INTimeofRestoration._CreationDate > TestDate) or TestDate = null:

                       TestDate = IncidentObj._INTimeofRestoration._CreationDate

                       LatestObj = IncidentObj

            • 3. Re: Calculation for DateTime Field from Incident to Problem
              Motaz ITSMMVPGroup

              What Julian said is correct. I have done something similar today using the below calculation:

               

              import System

              static def GetAttributeValue(Incident):

                   SortedItems = List(Incident.IncidentProblems as Collections.IEnumerable)

                   SortedItems.Sort() do (first, last):

                        return last.CreationDate.CompareTo(first.CreationDate)

                   Value = false

                   for item in SortedItems:

                        if item.Problem.Status.Title == 'Resolved' or item.Problem.Status.Title == 'Workaround Provided':

                             Value = true

              return Value

              • 4. Re: Calculation for DateTime Field from Incident to Problem
                rmastenbrook Rookie

                Thanks for the help! I was unable to make those work, however I was able to find a solution.

                Below is the calculation that gave the correct result:

                import System

                static def GetAttributeValue(Problem):

                       for IncidentLink in Problem.IncidentProblems:

                              if IncidentLink.Incident._INTimeOfIncident != null:

                                     Value = IncidentLink.Incident._INTimeOfIncident

                              return Value