1 Reply Latest reply on Jun 15, 2017 4:53 AM by ColinWalton

    Checking for current user Role in calculation

    ColinWalton Rookie

      There has been a thread on this subject in the past, however I have not been able to produce the results I require.


      We have a calculation that hides/shows attributes on a window based on the CI Type of the record.


      I now want to add a section that will perform the same attribute hide/show function, but based on a specific role assigned to the 'current user'.


      Below is a modified extract that I have come up with so far. The text in blue italics is effectively the code I am expecting to identify the current user and if they have been assigned the specified role.


      Testing the calculation is successful, however the attributes I would expect to show/hide based on the criteria below are not changing.


      Any help would be greatly appreciated!



      import System

      static def GetAttributeValue(Change):


                Value = ''

                hidePON = true

                hideEQC = true

                hidePUR = true

                hideSUP = true

                hideSUR = true


                CurrentUserName = Change.GetCurrentUserName()

                CurrentUserTitle = Change.GetObjectByAttribute("System.User", "Name", CurrentUserName)


                if Change._ConfigItemTypeReference != null:    

      for item in CurrentUserTitle.UserRoles:

                                   if item.Role.Title == 'IT Asset Manager':

                                           hidePON = false

                                            hideEQC = false

                                            hidePUR = false

                                            hideSUP = false

                                            hideSUR = false


        Value = String.Format(":SetHidden(_ClonePONumber, {0});:SetHidden(_CloneCost, {1});:SetHidden(_ClonePurchaser, {2});:SetHidden(_CloneSupplier, {3});:SetHidden(_CloneSupplierReference, {4});", hidePON, hideEQC, hidePUR, hideSUP, hideSUR)        


                return Value


      Message was edited by: Colin Walton I have resolved this now by adding the attribute '_Role/Title' as a dependency.