4 Replies Latest reply on Dec 20, 2017 1:09 AM by Anita.Carr

    A way to automatically return the currentuser in an action

    Anita.Carr Apprentice

      I am using the bulk actions feature in workspaces, which returns the created user as system. To get around this i have added another field of current user, that the person completing the action selects their own name. This has been added to the query so if its a system created entry then the current user value is used for audits.

      Is there a way to get the system to automatically select the current user in this field? I can then Hide it on the window.

      I am aware of the GetCurrentUser and GetObjectByAttribute functions so I have created a new linked object to user attribute in the object and saved it as a before save calculation as follows:

      import System

      static

      def GetAttributeValue(_TaskReceiveItem):

      TheUserName = _TaskReceiveItem.GetCurrentUser() 

      TheActualName = _TaskReceiveItem.GetObjectByAttribute("System.User", "Name", TheUserName)  

      return TheActualName.Title

       

      With the dependancy of the _TaskReceiveItem

       

      This is on Request tasks object

       

      After an IISRESET the current user field is still blank.

      Where am i going wrong? My coding knowledge is pretty basic.

        • 1. Re: A way to automatically return the currentuser in an action
          Julian Wigman ITSMMVPGroup

          Anita

           

          You could also use a Business Object Copy Rule as you can use with Initialisation when you use a macro value $CurrentUser$ but check the box not to overwrite as well as you dont want it to fire after creation ie when you open for read/update (if that is a possibility).

           

          Your calculation generally looks fine but it could be the value you are returning. Is the field this calculation on a string or related (dropdown) attribute;  if the latter then you return the object reference and not the title (as you do for the former)!  So your “TheActualName” variable is really an object reference so you can do this on a related use attribute ie return TheActualName

           

          Julian

          MarXtar Ltd

          • 2. Re: A way to automatically return the currentuser in an action
            Anita.Carr Apprentice

            Hi Julian,

            Thank you for the feedback. I have removed the title from the calculation as it is a object related field, however the field stays blank. I have it set with a Before Save calculation type and run an iisreset. even when I run it manually without the bulk action it stays blank. So dependancy? I have that set as the action object. I have added the field to the window - but not set any properties on this.

            I've not tried the business object copy rule as yet. Maybe thats the way forward.

            Thanks Anita

            • 3. Re: A way to automatically return the currentuser in an action
              Anita.Carr Apprentice

              I have now tried the copy rules in window manager. This updates the field. Works nicely when manually completed but alongside the bulk actions it updates the current user as System. Which is what I'm trying to get around automatically. Is there a way to update the user and save before the bulk action runs?

              • 4. Re: A way to automatically return the currentuser in an action
                Anita.Carr Apprentice

                Okay my mistake I had the copy rule set on create. Now changed to initialise and it all works with the bulk actions!

                Many thanks Julian

                Anita