Store Username as a Static Value

437
23
07-15-2019 02:02 PM
joerodmey
MVP Regular Contributor

I want to capture the username at specific times (Ex: when a user clicks a radio button) but it appears the username is always captured regardless of if its in a relavant based on a radio button. I also cant store it in a variable without it changing.

Any ideas?

thanks

0 Kudos
23 Replies
by Anonymous User
Not applicable

It would be a little tricky and depends on what the end game/goal is, but it sounds like you could possibly do the following -

  1. Create a question type of "username"
  2. Then you will need to create a new question that is the Yes/No select one question within your survey as you implied above.
  3. Create a hidden question directly below the question that you are having the user answer Yes/No to and within the "Calculation" field enter an if() function with a once() function embedded that will populate the username question's answer when the question is answered as "Yes".
  4. if(${NewQuestion}='Yes', once(${username}),'') should be the function that calls the answer of the username question once they answer "Yes".
0 Kudos
joerodmey
MVP Regular Contributor

I keep getting invalid calculate error. Basically I have 3 fields in play:

-my select one called Request_Status which has 3 selection options

-my username type called user_status

-my hidden field that stores the username called user_storage

on the hidden field called user_storage I'm running the following calculate: if(${Request_Status}='In_Progress', once(${user_status}),")

when I save my excel sheet I get the error mentioned above

0 Kudos
by Anonymous User
Not applicable

Hey Joe, looks like within your if statement you have a double quotation instead of two single quotes. 

if(${Request_Status}='In_Progress', once(${user_status}),") that should be two of these together.

If think if you change that up, then you should start to see some data following...

Cheers!

Mike

0 Kudos
joerodmey
MVP Regular Contributor

Error no longer exists but in testing it appears that my new field (user_status) which holds the username is changing if I login as a different user. I know this because I set this field to text for the meantime for testing

0 Kudos
by Anonymous User
Not applicable

Hey Joe,

The question type "username" will change with every time a different person logs into the Survey123 form. However, if you are using the once() on the hidden field, then it will only pull this variable once the select one question equals the stated value. If you expose the hidden question and then change the value of the select one question a couple of times to different values, then the username should not change.

0 Kudos
joerodmey
MVP Regular Contributor

But it appears that this hidden field which I have exposed through a text type also changes to the current username.

Just to clarify I want this hidden field to hold the user name who sets the select one to in progress and "locks" this username into this hidden field. if I were to login as another user this hidden field should never change even if this 2nd user changes the select one to in progress as well. 

0 Kudos
joerodmey
MVP Regular Contributor

Any ideas? Mike Bruening

0 Kudos
by Anonymous User
Not applicable

Hey Joe,

The form that I created seemed to work in the manner that you wanted to have happen. That Form is on my laptop at home and I will take a look at it tonight once I get home. I wonder if you can put the entire calculation into another "once()" and it work?

Like something below.

once(if(${Request_Status}='In_Progress',once(${user_status}),"))

0 Kudos
by Anonymous User
Not applicable

Hey Joe,

I tried to recreate this at lunch and it seems to work when you place the previous if() into a once() like I mentioned above. Let me know if that helped out and sorry for the delayed response as I have been very busy with some heavy-lifting on a few projects.

Mike

0 Kudos