Power Apps Exchange

Please login or click SIGN UP FOR FREE to create your PowerAppsUG account to join this user group.
 View Only
Expand all | Collapse all

Invalid arguments in Switch

  • 1.  Invalid arguments in Switch

    Posted 26 days ago

    Hello all, any ideas why this is giving me an invalid argument message:

    Switch(
        varProxyStatus,
        "Proxy_Liaison", varProxyEmail & ", " & With( {wString: Concat(col_liaisons, 'EMAIL ADDRESS' & ", ")}, Left(wString, Len(wString)-2)),
        "Liaison Only", With( {wString: Concat(col_liaisons, 'EMAIL ADDRESS' & ", ")}, Left(wString, Len(wString)-2)),
        "Proxy Only", varProxyEmail
        )

    The variable at the front of the statement is being pulled from a field value in a gallery on the page. I'm thinking the varProxyStatus variable needs an extension (but .Value and .Text) are not working. Suggestions?



    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------


  • 2.  RE: Invalid arguments in Switch

    Top Contributor
    Posted 25 days ago

    I believe it is your Concat function. You either use Concat or & not both. 

    Concat(col_liaisons, 'EMAIL ADDRESS' , ", ")



    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------



  • 3.  RE: Invalid arguments in Switch

    Posted 22 days ago

    Thanks Brian, I've removed the & symbol per your instructions, but I'm still getting an invalid Switch argument message. The latest rev looks like:

    Switch( varProxyStatus,

        "Proxy_Liaison", varProxyEmail & ", " & With( {wString: Concat(col_liaisons, 'EMAIL ADDRESS' , ", ")}, Left(wString, Len(wString)-2)),

        "Liaison Only", With( {wString: Concat(col_liaisons, 'EMAIL ADDRESS' , ", ")}, Left(wString, Len(wString)-2)),

        "Proxy Only", varProxyEmail

        )

    Sorry for the crappiness of this image, but the red underlines go away when I try to grab the image from Snip & Sketch.

    Maybe I'd be better off working with an IF statement? But this was an opportunity to use Switch, which I wanted to learn.



    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------



  • 4.  RE: Invalid arguments in Switch

    Top Contributor
    Posted 22 days ago

    In that case I think I will need more info about what the variables contain and what type they are. It could be a mismatch or an invalid value once it evaluates.

    Have you checked the actual value of the variables when the statement processes? You can just add some labels to the screen so you can make sure they are what you think they are.

    This is a great case for Switch so no worries on that.



    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------



  • 5.  RE: Invalid arguments in Switch

    Posted 22 days ago
    Edited by Rik Forgo 22 days ago

    Thanks, Brian. The varProxyStatus variable is pulling an OptionSetValue from a choice field in my Dataverse table, and I can confirm it pulls one of the three values I have listed in the Switch statement every time.

    • "Proxy_Liaison"
    • "Liaison Only"
    • "Proxy Only"

    Does the fact that it's pulling an OptionSetValue change things even though it's just a text value in a variable now?



    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------



  • 6.  RE: Invalid arguments in Switch

    Top Contributor
    Posted 22 days ago

    You can use anything for the Switch value - the variable you have is fine. Since it is complaining of an invalid argument it may be that one of the other variables you are using is what it is complaining about. I would try reducing the function to a single branch to see if it will take that. It could be that it is only complaining about one of the branches. If you can narrow that down it should be easier to find the error



    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------



  • 7.  RE: Invalid arguments in Switch

    Posted 22 days ago

    OK so I reduced the statement down to just the first condition, and it still fails there:

    The hover hint over the first conditional value says: "Invalid argument type (Text). Expecting an OptionValueSet instead."
    So it seems that the data type for an OptionValueSet is different than a text string. How should I format the "Proxy_Liaison" value so that PowerApps recognizes it as an OptionValueSet value? I've searched around for an example, but haven't really found one yet. The closest I came was to adding a [@varProxyStatus].'Proxy_Liaison' to the first test, but that didn't work. It throws an error from the period to the last single quote that says the name isn't recognized.
    It seems like this is a problem with OptionSetValue, but I'm not sure how to resolve it.


    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------



  • 8.  RE: Invalid arguments in Switch

    Top Contributor
    Posted 22 days ago

    OK - that means we have an entirely different issue - I missed that this was a choice column. The Choices are a table so I believe you need the Choices function to allow the system to work with them. I believe the syntax is [@ChoiceColumn].ChoiceValue, but you ay not need the quotes since the value does not contain spaces



    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------



  • 9.  RE: Invalid arguments in Switch

    Posted 22 days ago

    Yea, I just don't have a strong enough understanding of how the syntax in this instance should work. I did what you suggested here:

    But it's still throwing an error. FWIW, it is pulling a value from the table, but by the time the condition is evaluated it's in a variable. That appears to be the only issue with the Switch statement. The error on the screen is:
     "Name isn't valid. 'Proxy_Liaison' isn't recognized.
    I tried with single quotes and no quotes. Same error each time. Double quotes gives me  an unexpected operator and Unexpected character error. Still no joy.


    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------



  • 10.  RE: Invalid arguments in Switch

    Top Contributor
    Posted 22 days ago

    2 things to try - the first is you are missing a closing parenthasis - that's the easy fix. ;)

    if you erase the ".'Proxy_Liason" and then type in the period, does the program suggest a value to add?



    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------



  • 11.  RE: Invalid arguments in Switch

    Posted 22 days ago
    Edited by Rik Forgo 21 days ago

    Good catch on the closing paren. Adding it didn't help, and erasing everything and re-adding the period prompts me to add a match value.



    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------



  • 12.  RE: Invalid arguments in Switch

    Posted 18 days ago
    Edited by Rik Forgo 18 days ago

    Just to close the loop on this question. I was able to resolve it by converting the choice value to a text value when I set the variable. The variable was set from a gallery and the value was pulled from a choice field, but it retained its "choice" data type when the variable was created.  So I wrapped the creation of the variable in a Text() wrapper, and even though PowerApps told me this type of "scoping" wasn't supported, I tried it anyway and it did successfully convert the value to a text value.

    Set(varProxyStatus, Text(ThisItem.PROXY_STATUS));

    The Switch statement worked perfectly after.

    Brian, thanks for hanging with me and helping me step through all the permutations.



    ------------------------------
    Rik Forgo
    Writer/Editor
    ------------------------------



  • 13.  RE: Invalid arguments in Switch

    Top Contributor
    Posted 18 days ago

    Glad to hear you got it working - sorry I was absent for a bit - I was under the weather for a few days.

    Using the other method it may be that you needed to add the database name, but this seems like a fine way to do it



    ------------------------------
    Brian Scott
    Chief Creative Officer
    Concord NC
    ------------------------------