You are viewing limited content. For full access, please sign in.

Question

Question

Add username to field

asked on June 13, 2017 Show version history

we have a template with fields called : Secretary comment , Junior comment , Senior comment , Team leader comment , .......

the customer Requisite to add the username automatically on a field that he write on.

EX: when secretary opens the document and writes a comment in secretary comment , her Name need to be automatically written.and also for others.

Note that: these fields  are multi-value fields as there is not only 1 secretary or 1 junior ,.......

                   All users access the same document.

kindly advice   

 

0 0

Replies

replied on June 13, 2017

Good morning Amal,

This can be accomplished by creating a Workflow with a starting rule of Event Type "Entry Changed" on the relevant folder(s):

You can also add a condition for "Entry : Field" equals .... in order to specify the relevant field (I couldn't do it for my screenshot above because my VM isn't currently setup with a useful repo/template/fields).

Setup the Workflow to first use the "Find Entry" or "Find Entries" activity, as appropriate. Then, use the "Assign Field Values" activity to add the user's name to the appropriate multi-valued field in the template. 

I hope this helps! Good luck!

Rob

0 0
replied on June 15, 2017

Thanks for your response 

I made another scenario but with the same result

Retrieve field value then add username finally assign field value

 

the 2 ways make sense with single value 

but with multi-value in (Assign field values) i have to specify exactly the index of the field i want to store the value in and in my scenario it is variable it is the last index.

0 0
replied on June 15, 2017 Show version history

You will have to build your logic to determine which (if any) multivalue field has changed.  Once you have the changed multivalue field in a multivalue token, you can use the following script to add the initiator to the start of the data.

        Protected Overrides Sub Execute()
            'Write your code here.
            Dim sError As String = Nothing
            Dim sModified As String = "False"
            Dim oField as Object = GetTokenValue("MultiValueToken")
            Dim initiator as String = GetTokenValue("Initiator")
            Dim lstField As List(Of String) = New List(Of String)
            if oField.GetType.ToString = "System.String[]" Then
                Try
                    Dim lstVals As List(Of String) = New List(Of String)
                    For Each sVal As String In oField
                        lstVals.Add(sVal)
                    Next
                    Dim sLastVal As String = lstVals.Item(lstVals.Count - 1)
                    If Not sLastVal.StartsWith(initiator) Then
                        Dim newLastVal As String = initiator & " - " & sLastVal
                        oField.SetValue(newLastVal, oField.Length - 1)
                        sModified = "True"
                    End If
                Catch ex As Exception
                    sModified = "False"
                    oField = Nothing
                    sError = ex.Message
                End Try
            Else
                sModified = "False"
                oField = Nothing
                sError = "Field is not Multivalue"
            End If
            SetTokenValue("Modified", sModified)
            SetTokenValue("Error", sError)
            SetTokenValue("MultiField", oField)
        End Sub

Then if the script token Modified = true, replace template field value with script MultiField token.

1 0
replied on June 15, 2017

Thanks for posting this reply, Bert--it's a good reminder for me, as someone newer to LF, that scripting can be used for all sorts of fun stuff in Workflow.

Quick, slightly off-topic question: in your experience, are there performance differences or differences in ease-of-use between scripting in VB.NET vs. C#? I'm asking because I'm trying to determine what language to spend time on first.

0 0
replied on June 15, 2017 Show version history

I can do both C# and VB, but I find that with the syntax of C#, it takes me a lot longer to code adding all the semicolons and curly brackets into the code.  But I think a lot of it is that I learned VB first and so I think that syntax better.  As far as efficiency of the running code, I think that now in .NET, they are very comparable.

1 0
replied on June 16, 2017

Thanks!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.