1 Reply Latest reply on Mar 7, 2011 1:01 PM by Göran.Pettersson

    Setting a value to an relation through calculation!!

    Apprentice

      How do you set a value on a relation field.

       

      For example to set an value on the incident nto set a relation to a reference list. The result shoud be a "guid" in that field in the database.

       

      One example I have tried:

       

      Parent is a relationfield  to another incident.

       

      import System

      static def GetAttributeValue(Incident):

      for j in Incident.Parents: Value = j.Parent.Guid

      return Value

       

      Loggfile:

       

      Calculation
      Attribute Calculation Unsuccessful at 2011-03-07 17:13:32.244
      Calculation successful for Attribute [_ParentGuid] on Class Type [IncidentManagement.Incident]
      On Object : Key = [56dbbd24-2951-40d7-8a46-593cb7a57063]  Name = [59371]
      Calculated Value = [7b6231ee-768e-41dd-9964-c7014badeb71]
      FAILED
      Type mismatch when attempting to set attribute value _ParentGuid.

       

      Anybody have an idea how to succeed?

       

      Göran

       

        • 1. Re: Setting a value to an relation through calculation!!
          Apprentice

          Hello again!

           

          I found the solution!

           

          Example 1: Populate the right relation to a reference list in an incident out of the "name property" of the reference list.


          import System

          static def GetAttributeValue(Incident):

          Value = " Fristående"

          Value2 = "0"

          for j in Incident.Parents: Value2 = j.Parent.Id.ToString()

          if Value2 != "0": Value = "Underärende"

          return Incident.GetNamedObject ("IncidentManagement._ParentChild", Value)

           

          Returns the appropiate reference value.

           

           

           

          Example 2:

           

          I created a incident- incident relation where I want to  store the parent Id. An incident can only be child to one incident a time in this example. It is now more easy to see and link to the parent. It also helps me cut restrict the incident-incident default  query to only populate children. By creating a "relation" to the parent it helps to create filters that populates all attachments of underlying  incident at the parent level. 

           


          import System

          static def GetAttributeValue(Incident):

          for j in Incident.Parents: Value = j.Parent.Id.ToString()

          return Incident.GetNamedObject ("IncidentManagement.Incident", Value)

           

          Returns the right Incident where the Value is the Referenced converted to a string.

           

          I tried to "Count" the parents.parents collection but this does not seem to work!

           

          Göran