Need help in powershell code in the flow action of flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-06-2024 11:04 AM - edited ā03-06-2024 11:08 AM
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-06-2024 07:15 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-07-2024 01:18 AM - edited ā03-07-2024 03:06 AM
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.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-07-2024 01:39 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-07-2024 04:56 AM - edited ā03-07-2024 04:57 AM
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.