Need help in powershell code in the flow action of flow designer

Koyel Guha
Tera Contributor

Hi Team,

I am trying to update an existing code in the flow action to assign the phone number to the users automatically based on the selected location(city) as requested via catalog item.

There is Customized table where we have Dial Plan US and few cities under US 

KoyelGuha_0-1709751221849.png

Existing Code in the flow action of the flow designer.

If($dialplan -eq 'US')

{

XXXX-$dialplan-DialPlan

}

ElseIf ($dialplan -eq 'CA')

{

XX--$dialplan-$city-DialPlan

}

else 

{

X

}

 

We want to segregate the three cities (Miami,sanford,newyork) from the US dialplan

If($dialplan -eq 'US')

{

XXXX-$dialplan-DialPlan     eg.  XXXX-US-DialPlan   

}

If (City - Miami or Sanford or Newyork) 

{

XXXX-$dialplan-$city-DialPlan    eg.  XXXX-US-Sanford-DialPlan   

}

 

I have tried the below code but still it is taking the US command and not running the City command if I select Miami / Sanford/ NewYork in the catalog item.

 

If($dialplan -eq 'US')
{
If(($city -eq 'Miami') -or ($city -eq 'Sanford') -or ($city -eq 'Newyork'))
{

XXXX-$dialplan-$city-DialPlan 

}

else

{

XXXX-$dialplan-DialPlan 

}

}

Can someone tell me where I am doing wrong. Is there any mistake in the syntax.

 

Thanks in advance.

 

4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @Koyel Guha 

 

Can you please share some screenshots of your custom action where you have made use of PowerShell step to run the PowerShell script. Also, if possible, can you please share your complete script to debug it further.

 

I assume you must be using Get Catalog Item Variables action to collect the city input and then passing it to your custom action as an input. Inside the action, please ensure that you have mapped the right input from custom action to your step action. Also, apply a trim transformation function on the city input to get rid of whitespaces.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi Amit,

 

Thank you for your quick response. 

Please check the below code.  When I am requesting a number for user and the user belongs to sanford /huntvalley , it is not running $dialplan-$city-DialPlan (which is the 2nd line of the command) rather it is still going to the global US dialplan and showing US dialplan command.

 

 

 


If($dialplan -eq 'US')
{
 If(($city -in 'Hunt_Valley') -or ($city -in 'Sanford') -or ($city -in 'Riverside'))
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName CGVF-$dialplan-International
Grant-CsTenantDialPlan -Identity $usr -PolicyName CGVF-$dialplan-$city-DialPlan     //This part is different
Grant-CsTeamsEmergencyCallingPolicy -Identity $usr -PolicyName $city
Grant-CsTeamsEmergencyCallRoutingPolicy -Identity $usr -PolicyName $dialplan
}
else
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName CGVF-$dialplan-International
Grant-CsTenantDialPlan -Identity $usr -PolicyName CGVF-$dialplan-DialPlan
Grant-CsTeamsEmergencyCallingPolicy -Identity $usr -PolicyName $city
Grant-CsTeamsEmergencyCallRoutingPolicy -Identity $usr -PolicyName $dialplan
}
}

Thanks

 

Hi @Koyel Guha 

 

Please try with below PowerShell Script :

 

New-PSSession -credential $cred | Out-Null
Connect-MicrosoftTeams -Credential $cred | Out-Null
$array = @("NL", "FR", "AT", "BE", "PT", "HU", "RO", "SG")
Set-CsPhoneNumberAssignment -Identity $usr -PhoneNumber $mobile -PhoneNumberType DirectRouting

If($dialplan -eq 'US')
{
 If(($city -in 'Hunt_Valley') -or ($city -in 'Sanford') -or ($city -in 'Riverside'))
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "CGVF-$dialplan-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "CGVF-$dialplan-$city-DialPlan"     //This part is different
Grant-CsTeamsEmergencyCallingPolicy -Identity $usr -PolicyName $city
Grant-CsTeamsEmergencyCallRoutingPolicy -Identity $usr -PolicyName $dialplan
}
else
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "CGVF-$dialplan-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "CGVF-$dialplan-DialPlan"
Grant-CsTeamsEmergencyCallingPolicy -Identity $usr -PolicyName $city
Grant-CsTeamsEmergencyCallRoutingPolicy -Identity $usr -PolicyName $dialplan
}
}
ElseIf ($dialplan -eq 'CA')
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "CGVF-$dialplan-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "CGVF-$dialplan-DialPlan"
Grant-CsTeamsEmergencyCallingPolicy -Identity $usr -PolicyName $city
Grant-CsTeamsEmergencyCallRoutingPolicy -Identity $usr -PolicyName $dialplan
}
ElseIf ($dialplan -in $array)
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "CGVF-$dialplan-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "CGVF-$dialplan-DialPlan"
}
ElseIf ($dialplan -eq 'ES')
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "VF-ES-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "VF-ES-Granollers-DialPlan"  
}
ElseIf ($dialplan -eq 'UAE')
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "CG-UAE-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "CG-UAE-DialPlan"  
}
else
{
Grant-CsOnlineVoiceRoutingPolicy -Identity $usr -PolicyName "VF-$dialplan-International"
Grant-CsTenantDialPlan -Identity $usr -PolicyName "VF-$dialplan-DialPlan"
}

 

Whenever we define a string including variables, you should either make use of either concatenation (+) operator or encode the string in double quotes. Please check and share the results.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hello Amit,

 

I have figured out the mistake which I was doing. The command is fine . I was taking incorrect city value. Rest everything was fine.

Thank you so much for trying and for the quick response.