3 Replies Latest reply on May 3, 2017 4:58 AM by bezkarl

    Exclude nulls from List/Sort calculations

    Apprentice

      Hi,

       

      I am using the following calculation to obtain a "journal"/summary of assignments in an incident:

       

      import System

      static def GetAttributeValue(Incident):

          SortedAssign = List(Incident.Assignments as Collections.IEnumerable)

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

              return last.CreationDate.CompareTo(first.CreationDate)

         

          Value= "<br>"

          for Assignments in SortedAssign:

              Value += String.Format("\r\n <font color='#214282' size='2'><b>Assignment Date:</b></font> <font size='2'><i>{0}</i></font> <font color='#214282' size='2'><b>Added By:</b></font> <font size='2'><i>{1}</i></font><br><br> <font size='2'>{2}</font><br><br><hr>",Assignments.CreationDate.ToLocalTime().ToString("dd.MM.yyyy h:mm tt"), Assignments.CreationUser.Title, Assignments._ReasonforReassignLarge)

          return Value

       

      There are occasions when the assignment reason/text will be null, and if possible I want to exlude these from the output.

       

      Does anyone know if this is possible and if so could please point me in the right direction?

       

      Kind regards,

       

      Karl

        • 1. Re: Exclude nulls from List/Sort calculations
          andreas.lindner Expert

          Hi Karl,

           

          should be possible. In your for loop add an If that looks like this:

               if Assignments._ReasonforReassignLarge != null:

                    Value += String.Format(.....)

           

          Or turn the comparison around and use this:

               if Assignments._ReasonforReassignLarge == null:

                    Value += String.Format(....,Assigments.CreationUser.Title, "No Details")

           

          That should do the trick.

           

          Andreas

          1 of 1 people found this helpful
          • 2. Re: Exclude nulls from List/Sort calculations
            Apprentice

            Thanks Andreas I will give it a go and let you know how I get on.

             

            Kind regards,

             

            Karl

            • 3. Re: Exclude nulls from List/Sort calculations
              Apprentice

              Hi Andreas,

               

              I went with your second solution as I didn't really want entries to be removed from the summary altogther so the assignment details and timestamp are still seen.

               

              Here is my relevant code:

               

              Value= "<br>"

                  for Assignments in SortedAssign:

                 if Assignments._ReasonforReassignLarge == null:
                 Value += String.Format("\r\n <font color='#214282' size='2'><b>Assignment Date:</b></font> <font size='2'><i>{0}</i></font> <font color='#214282' size='2'><b>Added By:</b></font> <font size='2'><i>{1}</i></font><br><br> <font size='2'>{2}</font><br><br><hr>",Assignments.CreationDate.ToLocalTime().ToString("dd.MM.yyyy h:mm tt"),Assignments.CreationUser.Title, "<font size='3'><b>Automatic assignment</b></font>")
                 if Assignments._ReasonforReassignLarge != null:
                 Value += String.Format("\r\n <font color='#214282' size='2'><b>Assignment Date:</b></font> <font size='2'><i>{0}</i></font> <font color='#214282' size='2'><b>Added By:</b></font> <font size='2'><i>{1}</i></font><br><br> <font size='2'>{2}</font><br><br><hr>",Assignments.CreationDate.ToLocalTime().ToString("dd.MM.yyyy h:mm tt"), Assignments.CreationUser.Title, Assignments._ReasonforReassignLarge)

                  return Value

               

              There are occasions where the analysts enter a ' ' (blank value) into the text (and they shouldn't!), which is not a null value, so as it stands this will show as blank in the summary. I have tried if Assignments._ReasonforReassignLarge == null or ' ': in the first if statement which works to meet the criteria, but as the blank value also meets the second if statement it adds the summary detail twice. Adding if Assignments._ReasonforReassignLarge != null or ' ' doesn't seem to work.

               

              I'm not too bothered about this as I am happy for the summary text to show as blank, but do you have any ideas?

               

              Kind regards,

               

              Karl