Highlighted
forumadmin Absent Member.
Absent Member.
10794 views

Wondering how to set "current user" for a single-selection field


Question posted 4/6/08 by Ross Pearson
Details:
Hi again,
I was wondering if anybody could help me with this issue. I have a feeling the answer might require some TeamScript, but at the moment I'm woefully inept at all things script related.
I have a workflow that has a single-relational field, called "User Name", that looks up usernames in my Contacts Table. I have done this rather than create a new User field so that I can link to the sub-relational information in the contacts table, ie, phone number, location, email address, etc,. and have it show in transitions and states.
I've noticed that I cannot link to this information from the existing User type fields, ie, submitter, last modifier, etc.
So now I just need to know how to get my new Single-Relational "User Name" field to automatically display who the current user is, rather than requiring the user to manually select themselves from the list when submitting.
Essentially, I need something along the lines of "User Name = Submitter", as there is no option to set User Name to <currentUser>.
Thanks for your assistance!
˜Ross Pearson
0 Likes
7 Replies
forumadmin Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


Comment posted 4/6/08 by Peter Rooke
Give this a try to set the Contact field to the Current User during the Submit transition:
Edit the Project, not the Workflow, at the highest level that applies in the project hierarchy.
Edit the Submit transition.
In the Fields tab, select the Contact field and choose Edit.
In the Attributes tab, check ON Allow Override and for Action on the same dialog, select 'Set Value to Default Value'.
In the Options tab, drop down the Default Value field, and then ABOVE the (None) choice you will find Current User.
0 Likes
forumadmin Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


Comment posted 4/6/08 by Peter Rooke
My previous comment works for User fields but not for Single Relational Fields.
I would use a post-transition script (on the Submit transition) to set the Contact (Single Relational Field) = to the Submitter. Here is the code. Test it 🙂
Note use of the UPPER CASE field names tells Business Mashups that you are specifying the Database Name of the field not the Display Name.
Call Shell.Item.GetFieldValue( "SUBMITTER", sContact )
Call Shell.Item.SetFieldValue( "CONTACTNAME", sContact )
0 Likes
forumadmin Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


Comment posted 4/7/08 by Ross Pearson

Just wanted to leave a comment that I've been in contact with Peter via email all day today regarding this (Great Guy, excellent service), and we're approaching a solution.
The script currently looks like this:
Option Explicit
Dim fldList, fldObj, sContact
Set fldList = Shell.Item.Fields()
Set fldObj = fldList.FindField( "SUBMITTER" )
Call fldObj.GetDisplayValue( sContact )
Call Shell.Item.SetFieldValue( "REQUESTED_BY", sContact )
Unfortunately the value from SUBMITTER is not currently changing the value in REQUESTED_BY (which is a single-relational field to my TS_CONTACTS system auxiliary table).
We've determined that in order for this to work, we need to determine:

1. The Submitters ID is from the TS_USERS table.
2. The Contacts ID is from the TS_CONTACTS table.
3. These can be and often are different numbers for the same person.
4. It would appear that the relational fields require to be set with the ID rather than the display value.
So we need to code for this and test it out.
If anybody else has any comments or suggestions, they would be greatly appreciated!
Thanks,
˜Ross Pearson

0 Likes
forumadmin Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


Comment posted 4/9/08 by Peter Rooke
To have TeamTrack automatically set the Contact field to the Submitter, do these steps:
1) Add the Contact as a Single Relational Field to the workflow
2) Make sure the users are defined with the 'Create/Update Record from User' setting ON, rather than 'Don't Update Contact Record'.
3) Don't write a bunch of script to try to make it work 🙂
That works for me 🙂 Let us know how you go, Ross.
0 Likes
forumadmin Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


Comment posted 4/10/08 by Peter Rooke
Although TeamTrack should set the Contact, it doesn't in Ross's case. Here's the code to make it work anyway:
Option Explicit
Dim contactRec, whereClause, fldList, fldObj, sSubmitter, sSubmitterFirstName, sSubmitterLastName, sContactID, ptr
' get submitter's name
Set fldList = Shell.Item.Fields()
Set fldObj = fldList.FindField("SUBMITTER")
Call fldObj.GetDisplayValue(sSubmitter)
' get Submitter's first name & last name
ptr = InStr(sSubmitter, " ") - 1
sSubmitterFirstName = Left(sSubmitter, ptr)
ptr = ptr + 2
sSubmitterLastName = Mid(sSubmitter, ptr)
' get the Contact ID where the submitter's name = contact's name and set CONTACT field
Set contactRec = Ext.CreateAppRecord(Ext.TableId ("TS_CONTACTS"))
whereClause = "((TS_CONTACTFIRSTNAME = '" & sSubmitterFirstName & "') AND (TS_CONTACTLASTNAME = '" & sSubmitterLastName & "'))"
If contactRec.ReadWithWhere(whereClause) Then
sContactID = contactRec.GetId()
Call Shell.Item.SetFieldValue("CONTACT", sContactID)
Else
Call Ext.LogInfoMsg("Submitter " & sSubmitter & " has no Contact record")
End If
0 Likes
forumadmin Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


Comment posted 3/23/09 by Dave Grimm

I too would like to have the Current User info be the default info displayed in a single relational field. This seems to be the case for TeamTrack solutions, but not Business Mashups. Does the above code work because it doesn't work for me? Are there other pre-requisites like displaying the CONTACTFIRSTNAME field and the CONTACTLASTNAME field from the CONTACTS table etc..?

0 Likes
adil_k_hussain Absent Member.
Absent Member.

Re: Wondering how to set "current user" for a single-selection field


I know it's an old thread. but just in case; the above code works for me.

Have you checked that your field name is correct in this line

Call Shell.Item.SetFieldValue("CONTACT", sContactID)

Here Peter is using "CONTACT" as a field name. In my case, it was "REQUESTER."

When I changed that, the code worked for me.

Regards,

--Adil
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.