Home > Software engineering >  Toast Notification - Open a web page with specific character on the link
Toast Notification - Open a web page with specific character on the link

Time:10-08

I have created a toast notification using Powershell and XML to show some information and now I wanted to use a button to redirect the user a specific web page.
The is that on the web link, there is specific character as '=' and I always get an error. I try to use a variable, different type of quotes and now I am a bit stuck. The error I got is:

Error: "'=' is an unexpected token. The expected token is ';'.

And the code:

[xml]$Toast = @"
<toast scenario="$Scenario">
    <visual>
    <binding template="ToastGeneric">
        <group>
            <subgroup>
                <text hint-style="title" hint-wrap="true" >$TitleText</text>
            </subgroup>
        </group>
        <group>
            <subgroup>
                <text hint-style="Body" hint-wrap="true" >$BodyText1</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="base" hint-wrap="true" >$BodyText2</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="body" hint-wrap="true" >$BodyText3</text>
            </subgroup>
        </group>
    </binding>
    </visual>
    <actions>        
        <action arguments="https://part_of_the_link.aspx?C_ECRAN=HELP5_REQ_SYS&Type=LINK&Action=A&FieldName=C_OBJETSERVICE&FieldValue=THING" content="Open Web Page" activationType="protocol" />
        <action activationType="system" arguments="dismiss" content="$DismissButtonContent"/>
    </actions>
</toast>
"@

CodePudding user response:

The error message might be throwing you off, as the problem with the URL is not actually the =, but the fact that you haven't escaped the literal ampersands (&) preceding the param=value pairs in the string.

Easiest way to escape the string in PowerShell is probably with [SecurityElement]::Escape():

[xml]$Toast = @"
<toast scenario="$Scenario">
    <visual>
    <binding template="ToastGeneric">
        <group>
            <subgroup>
                <text hint-style="title" hint-wrap="true" >$TitleText</text>
            </subgroup>
        </group>
        <group>
            <subgroup>
                <text hint-style="Body" hint-wrap="true" >$BodyText1</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="base" hint-wrap="true" >$BodyText2</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="body" hint-wrap="true" >$BodyText3</text>
            </subgroup>
        </group>
    </binding>
    </visual>
    <actions>        
        <action arguments="$([System.Security.SecurityElement]::Escape('https://part_of_the_link.aspx?C_ECRAN=HELP5_REQ_SYS&Type=LINK&Action=A&FieldName=C_OBJETSERVICE&FieldValue=THING'))" content="Open Web Page" activationType="protocol" />
        <action activationType="system" arguments="dismiss" content="$DismissButtonContent"/>
    </actions>
</toast>
"@
  • Related