web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Use a switch statement...
Power Apps
Answered

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

(0) ShareShare
ReportReport
Posted on by 180

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.

Categories:
I have the same question (0)
  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    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 Profile Picture
    180 on at

    Thank you very much.

  • GeminiWorks Profile Picture
    180 on at

    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

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 421

#2
WarrenBelz Profile Picture

WarrenBelz 345 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 278 Super User 2026 Season 1

Last 30 days Overall leaderboard