MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.22k stars 21.37k forks source link

Nesting for function SelectUniqueValue not working #119448

Closed sergiopadure closed 7 months ago

sergiopadure commented 7 months ago

Hi,

Has anyone found a solution to the need of nesting SelectUniqueValue?

We need to be able to select the domain of the email address of the provisioned user depending on the value of employeeClass on the side of SuccessFactors.

I've tested this:

Switch([employeeClass], Join("@", Join("", "CORP", [personIdExternal]), "contoso.com"), 
"123", SelectUniqueValue( 
    Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]))))), "contoso.com"), 
    Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "A")))), "contoso.com"),
    Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "B")))), "contoso.com")
), 
"124", SelectUniqueValue( 
    Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]))))), "external.contoso.com"), 
    Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "A")))), "external.contoso.com"),
    Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "B")))), "external.contoso.com")
))

But returns an error saying that SelectUniqueValue cannot be nested.

So I rotated the usage of the functions to this:

SelectUniqueValue( 
    Switch([employeeClass], Join("@", Join("", "CORP", [personIdExternal]), "contoso.com"), "123", Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]))))), "contoso.com"), "124", Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]))))), "external.contoso.com")), 
    Switch([employeeClass], Join("@", Join("", "CORP", [personIdExternal]), "contoso.com"), "123", Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "A")))), "contoso.com"), "124", Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "A")))), "external.contoso.com")), 
    Switch([employeeClass], Join("@", Join("", "CORP", [personIdExternal]), "contoso.com"), "123", Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "B")))), "contoso.com"), "124", Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".",  Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "B")))), "external.contoso.com"))
)

But this returns an array of values instead of the first Unique: ["name.surname@external.contoso.com","name.surname.a@external.contoso.com","name.surname.b@external.contoso.com"]


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

AjayBathini-MSFT commented 7 months ago

@sergiopadure It would be great if you could add a link to the documentation you are following for these steps? This would help us redirect the issue to the appropriate team. Thanks!!

sergiopadure commented 7 months ago

@sergiopadure It would be great if you could add a link to the documentation you are following for these steps? This would help us redirect the issue to the appropriate team. Thanks!!

Hi, I've been using this as reference: https://learn.microsoft.com/en-us/entra/identity/app-provisioning/functions-for-customizing-application-data

But going a bit beyond what's indicated there because of our specific needs.

AjayBathini-MSFT commented 7 months ago

@sergiopadure Thanks for your feedback! We will investigate and update as appropriate.

AjayBathini-MSFT commented 7 months ago

@sergiopadure

Hello! It seems like you are still trying to generate unique email addresses for each user based on their employeeClass value, but the expressions you have tried so far are not giving you the desired result.

To generate a unique email address for each user based on their employeeClass value, you can try using the following expression:

Join("@", NormalizeDiacritics(StripSpaces(ToLower(Join(".", Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]))))), Switch([employeeClass], "CORP", Join("", [personIdExternal], "@contoso.com"), "123", SelectUniqueValue(Join(".", Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "a", "@contoso.com"), Join(".", Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "b", "@contoso.com")), "124", SelectUniqueValue(Join(".", Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "a", "@external.contoso.com"), Join(".", Coalesce([preferredName], [firstName]), Coalesce([preferredSurname], [lastName]), "b", "@external.contoso.com"))) This expression uses the Switch function to determine the domain based on the value of employeeClass, and then concatenates it with the email address generated by the Join function. For the "123" and "124" cases, it uses the SelectUniqueValue function to generate a unique email address based on the user's name and a suffix.

Let me know if this helps!

sergiopadure commented 7 months ago

@AjayBathini-MSFT I don't think a Copilot/ChatGPT answer would help here, especially since that was one of the first things I tried myself...

As indicated within my post, SelectUniqueValue cannot be nested, so the AI-generated expression you've provided wouldn't work.

AjayBathini-MSFT commented 7 months ago

@sergiopadure Thanks for your feedback! I've assigned this issue to the author who will investigate and update as appropriate.

lorieide commented 7 months ago

This function SelectUniqueValue can not be nested, as indicated in documentation.

lorieide commented 7 months ago

please-close

sergiopadure commented 7 months ago

This function SelectUniqueValue can not be nested, as indicated in documentation.

* This function must be at the top-level and cannot be nested.

As indicated in the message I'm very aware of that, which is why I was looking for an additional solution, but nesting switch doesn't work either as switch is not outputting the array of strings it's supposed to but rather an array of arrays which then SelectUniqueValue cannot parse...

sergiopadure commented 7 months ago

please-reopen