4 Replies Latest reply on Feb 10, 2016 11:44 AM by Fabian Schmidt

    Calculation Help!:  Current User is User Selected in a Collection/Object and more!

    Expert

      Hi all,

       

      We are currently on Service Desk version 7.7.1 and I am trying to create a new condition using a calculation within the Incident Management module.  There are two objects/collections that I need to check and verify.

       

      The first collection/object is called Project Approvals (_ProjectApprovals), the attribute which is the focus is Approver2 (_Approver2) which was created by dropping System.User on the _ProjectApprovals Object.

           -     For this I need to find out if the Current User (person logged in looking at the Incident ticket) is the same person as the latest selected person in the Approver2 (_Approver2) attribute within the Project Approvals (_ProjectApprovals) collection

       

      After figuring that out, I need to move to the second requirement:

       

      The second collection/object is called SR Project Gates (_SRProjectGates), the attribute which is the focus is a reference list called SR Project Transitions (_SRProjectTransitions).

           -     For this I need to find out if the latest _SRProjectTransitions selection is "A" or "B".

       

      My plan was to build this up and test on the way, but I am stuck on the first requirement listed above.  The last several versions of that calculation are listed below.

       

      Version 1:

      import System
      static def GetAttributeValue(Incident):
          Value = 'False'
          CurrentUser = Incident.GetCurrentUserName().ToLower()
          UserName = Incident.GetObjectByAttribute("System.User", "Name", CurrentUser)
          if Incident._ProjectApprovalsCol._Approver2 != null:
              Approver = Incident._ProjectApprovalsCol._Approver2.Latest().Name.ToLower()    
          if Approver == UserName:
              Value = 'True'
          return Value
      

       

       

      Version 2:

      import System
      static def GetAttributeValue(Incident):
          Value = 'False'
          CurrentUser = Incident.GetCurrentUserName().ToLower()
          UserName = Incident.GetObjectByAttribute("System.User", "Name", CurrentUser)
          if Incident._ProjectApprovalsCol["_Approver2"] != null:
              Approver = Incident._ProjectApprovalsCol["_Approver2"].Latest().Name.ToLower()    
          if Approver == UserName:
              Value = 'True'
          return Value
      

       

       

      Version 3:

      import System
      static def GetAttributeValue(Incident):
          Value = 'False'
          CurrentUser = Incident.GetCurrentUserName().ToLower()
          if Incident._ProjectApprovalsCol != null:
              if Incident._ProjectApprovalsCol._Approver2 != null:
                  if CurrentUser == Incident._ProjectApprovalsCol._Approver2.Latest().Name.ToLower():
                      Value = 'True'
          return Value
      

       

       

      Thanks for any assistance!