6 Replies Latest reply: Jan 18, 2012 9:55 AM by Stu McNeill RSS

    Using Calculations to copy dates from one process to another

    keithr Specialist

      When creating a change from within a service request, I would like the ability to copy the “implementation date” specified on the request to the change request.

       

      Have tried this using the following calculation:

       

      import System

      static def GetAttributeValue(Change):

      Value = Change.RequestChanges.Incident._TargetDate

      return Value

       

      The Calculation has been added to the Change.Target date on the automatic “create change” action within the request process but the copy does not initiate.

       

      The attribute is a date attribute and is not selectable if I try to use Value Types as you might with a string.  If anyone has successfully copied a date from one process to another, would appreciate knowing how this was achieved.

        • 1. Re: Using Calculations to copy dates from one process to another
          Stu McNeill Employee

          Hi Keith,

           

          This actually came up yesterday in another thread and should give you the answer: Value Types & Dates

          • 2. Re: Using Calculations to copy dates from one process to another
            keithr Specialist

            Hi Stu,

             

            Thanks for pointing me in the right direction.  I ran into errors but presume that it is something I am updating incorrectly in my calculation as it is based on the Incident.change object.  I tried a combination of updates to my calculation (which is actually this, since the customer uses the incident domain for their request process)

             

            import System

            static def GetAttributeValue(Change):

            Value = Change.IncidentChanges.Incident._TargetDate

            return Value

             

             

            I tried replacing "Parent" or "ParentLink" with Change.IncidentChanges but just ran into errors.  Any suggestions greatly appreciated.

             

             

             

            • 3. Re: Using Calculations to copy dates from one process to another
              Stu McNeill Employee

              Hi Keith,

               

              The important point of the other thread is that you can't just reference the collection, you need to use a For loop to get the attached Incident.  In your case IncidentChanges is a collection that could have multiple Incidents attached.  You need to decide which incident you want to get the Date from.  If there will only every be one incident attached you can just do the same trick I suggested in the other thread of looping through and setting the incident to a variable.

               

              I hope that helps.

              • 4. Re: Using Calculations to copy dates from one process to another
                SDESK Apprentice

                Thanks Stu,

                 

                I have had a play with the loop calculation but ran into some errors.  Can you tell me what "ParentLink" relates to in your post.  I am presuming "Parent" in my case would be "IncidentChanges" but just not sure what to substitue "ParentLink" for:

                 

                Example from previous post:

                Parent = null
                     for ParentLink in Request.Parents:
                          Parent = ParentLink.Parent

                 

                     if Parent == null: return null
                     else: return Parent._UserStartDate

                • 5. Re: Using Calculations to copy dates from one process to another
                  Stu McNeill Employee

                  Hi,

                   

                  I was planning on writing a full document explaining loop techniques but haven't had a chance yet.  Your latest calculation looks like it should work so it depends what error you're getting as to what the problem is now.

                   

                  Basically "ParentLink" is just a name you give for when you reference each item in the loop.  You can call it whatever you want:

                   

                  for Stu in Incident.Notes:

                       Value = Stu.Title

                   

                  In my case I called it ParentLink because each item in the Parents collection is the linking object record so it seemed a sensible name.

                  • 6. Re: Using Calculations to copy dates from one process to another
                    Stu McNeill Employee

                    Sorry I just realised the calculation you put into your last post wasn't what you're trying to use.

                     

                    In your case you don't need to rename ParentLink but you could call it "ChangeLink" or something similar so it makes more sense, then within the loop where I reference "ParentLink.Parent" you'd change the ".Parent" to ".Change" or ".Incident" to get to the record on the other end of the link.