Forum Discussion

Patrick75's avatar
Patrick75
Copper Contributor
Aug 21, 2025

Help with Expression

I am trying to build an expression in the cloud sync config.

 

I'm writing entra groups back on prem and I want to send them to different OUs based on the displayName as per this example:

    • Under Target container select Edit attribute mapping.
  1. Change Mapping type to Expression.
  2. In the expression box, enter:
  3. Switch([displayName],"OU=Groups,DC=contoso,DC=com","Marketing","OU=Marketing,DC=contoso,DC=com","Sales","OU=Sales,DC=contoso,DC=com")
  4. Change the Default value to be OU=Groups,DC=contoso,DC=com.

Problem with that approach is Id have to have a switch statement for every single displayName! what Id really like to do is direct my groups to an OU based the the first few sections of the display name.  So my groups would be named  "APP-APPNAME-USERS" for example and Id want the APPNAME section to be used in the switch function to send the groups to their respective OUs.  

The documentation says I can use nested expressions, so I have been trying to SPLIT the displayName in the switch expression but it isnt working at all.

Switch(Item(Split([displayName], "-"), 1), "APP1", "OU=APP1,OU=Application,OU=Groups,DC=contoso,DC=net", "APP2", "OU=APP2,OU=Application,OU=Groups,DC=contoso,DC=net", "APP3", "OU=APP3,OU=Application,OU=Groups,DC=contoso,DC=net", "OU=Application,OU=Groups,DC=contoso,DC=net")

Is anyone able to help with this?


1 Reply

  • Patrick75's avatar
    Patrick75
    Copper Contributor

    I spent all day on this and then worked out how to do it 5 minutes after posting this!

    If it helps anyone else, I went with this expression

    Append("OU=", Append(Item(Split([displayName], "-"), 2), ",OU=Application,OU=Groups,DC=contoso,DC=net"))

    Obviously targeted at the "parentDistinguishedName" attribute.  Worked like a charm

Resources