5 Replies Latest reply on Dec 17, 2014 9:43 AM by dmshimself

    calculation : check current user in users group

    Apprentice

      hi,

       

      Via a calculaion, I need to check if current user is in users's group from category object.

       

       

      Import System

      static def GetAttributeValue(Request):

          Value = false

          currentuserName = Request.GetCurrentUserName().ToLower()

          for grp  in Request.Category._CONSGrpValFonc.UserGroups:

              item = grp.User

              if item.Name.ToLower() == currentuserName.ToLower() :

                  value = true

          return Value

       

       

      syntax is correct however if I test calculation I have an error message : cannot read attribute value 'UserGroups' of class type system. group

       

      Has anyone any ideas please ?

       

      Thanks

       

      Regards

        • 1. Re: calculation : check current user in users group
          ITSMMVPGroup

          LANDESK consider that a calculation on UserGroups could produce a very lengthy calculation and so stop you from doing this,  It is possible to adjust this behaviour, but you'd need to contact support and discuss whether you want to go along that route.  I've used very similar calculations myself and it has always been fine, but that's not a definitive answer.  Also I'd adjust your calculation and instead of value = true, use return  true. That way as soon as you have found a group that matches, the calculation will stop searching.

          • 2. Re: calculation : check current user in users group
            Apprentice

            Thanks for your response,

             

            If LANDESK considers that is not a good manner by doing this, how can I do it differently ?

             

            I replaced value = true  with use return but I always having the same error

            Log :

            Calculation

            Lifecycle Condition Calculation Unsuccessful at 2014-12-14 21:54:03.888

            Calculation successful on Class Type [RequestManagement.Request]

            On Object : Key = [a580362e-b7cf-4c98-b57f-d12169cea7de]  Name = []

            Calculated Value = []

            FAILED

             

            Best Regards

            • 3. Re: calculation : check current user in users group
              ITSMMVPGroup

              I'd contact your local support team and take advice from them. Personally I think this sort of calculation should be allowed as long as people know the consequences of what they are doing. If you get an answer from support it would be great to see it up here.

              • 4. Re: calculation : check current user in users group
                Apprentice

                Hi,

                 

                I have found a solution for this ( until having news from Support) using GetObjectByAttribute

                This works correcttly

                 

                import System
                  static def GetAttributeValue(Request):
                      value = false
                      currentUser = Request.GetObjectByAttribute("System.User", "Name", Request.GetCurrentUserName())
                      for item in currentUser.UserGroups:
                          grp = item.Group
                          if Request.Category._CONSGrpValFonc != null:
                              if (grp.Title == Request.Category._CONSGrpValFonc.Title):
                                  value = true
                      return value


                Regards

                1 of 1 people found this helpful