1 Reply Latest reply on Jan 10, 2013 5:35 AM by Stu McNeill

    Calculation help on collections

    Darren.Bradshaw Expert

      I want to set a Boolean field on in the incident form to be true if a field on any item in a collection on the incident is set to true.


      On our incident table we have a collection called OrderItems, and if the field "Chargeable" it set to true on any of the items for that incident then the calculation sets the field on the incident form to true.


      This is my calculation at the moment


      Type: Before Save


      import System

      static def GetAttributeValue(Incident):

      #value = false

      #for item in Incident._OrderedItemsCol:

      ##if item._Chargeable == true:

      ###value = true

      ##return value


      Dependencies _OrderedItemsCol

      # = 1 Space


      It works, if on the first item in the collection the field is true.  But if the first item is set to false and the second item is set to true, my calculation does not work.



        • 1. Re: Calculation help on collections
          Stu McNeill Employee

          Hi Darren,


          There could be a couple of things happening here but the first thing is to check if the _Chargeable attribute can also be null as well as true or false.  You can set a default value of false in the object design to stop that, or add another condition to the if statment in your calculation to check it:


          for item in Incident._OrderedItemsCol:
               if item._Chargeable != null and item._Chargeable == true: value = true


          If that doesn't help I would suggest turning on the calculation logging to see if there are any errors logged when it runs.