cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GeminiWorks
Helper IV
Helper IV

Use a switch statement to provide a different value than what's given in the data card

Can I use a switch statement to send a different value to my sql database?

 

I have a data card that sends the username to the sql table.  However, I need to push a different user value.

 

Example:

ContactIDLog = username (Frank E Stein)

I want it to switch the username to Frank E Steing LOGGED

I need to do this for all users who log in and the switch will provide the different username based on who is logged in.

 

I'm not using a drop down because I don't ask users to select their username.  I simply provide it.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

For now I'll presume you have the field on the form, but that specific data card or field is set to not be editable on the Form. If so, I presume you use the Default property of the Data Card to decide what value is on the Form (and thus, what will be sent).

 

I'll also presume for now that it's possible to tell who is logged in or not by checking it somewhere in your database, with something like a simple LookUp.

 

So if that's the case:

 

First, use a variable for the username data card's Default, instead of a hard coded value

 

varUsername

 

 

Just prior to the submit (i.e. this is usually done on the OnSelect property of your Submit button) you can perform a Lookup against your data source to check if they are logged in, assuming you have a way to do this, and then set the variable value accordingly.

 

Now, on the OnSelect property of your Submit button

 

//pseudocode
Set
(
    varUsername
   ,If
   (
       Lookup(...).Logged_in
      ,"whateverYouWant" & "(LOGGED)"
      ,"whateverYouWant"
   )
)

 

 

The above should be modified for your scenario.

 

Check if it helps @GeminiWorks 

View solution in original post

3 REPLIES 3

For now I'll presume you have the field on the form, but that specific data card or field is set to not be editable on the Form. If so, I presume you use the Default property of the Data Card to decide what value is on the Form (and thus, what will be sent).

 

I'll also presume for now that it's possible to tell who is logged in or not by checking it somewhere in your database, with something like a simple LookUp.

 

So if that's the case:

 

First, use a variable for the username data card's Default, instead of a hard coded value

 

varUsername

 

 

Just prior to the submit (i.e. this is usually done on the OnSelect property of your Submit button) you can perform a Lookup against your data source to check if they are logged in, assuming you have a way to do this, and then set the variable value accordingly.

 

Now, on the OnSelect property of your Submit button

 

//pseudocode
Set
(
    varUsername
   ,If
   (
       Lookup(...).Logged_in
      ,"whateverYouWant" & "(LOGGED)"
      ,"whateverYouWant"
   )
)

 

 

The above should be modified for your scenario.

 

Check if it helps @GeminiWorks 

GeminiWorks
Helper IV
Helper IV

Thank you very much.

I am coming back on this one.  The solution made sense to me so I accepted.  However, now that I am working on my app, PowerApps does not recognize varUsername as valid.  I tried the card default and the log default.  Any idea on why varUsername is not recognized?  It only recognizes var_Contact and VarP.

 

GeminiWorks_0-1664310259617.png

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,757)