question

AndrewPerry-3419 avatar image
0 Votes"
AndrewPerry-3419 asked StefanHorz answered

Handling potential apostrophe's and quotes in a subscribed variable

Hi,

I am bringing in data from ServiceNow "Description" field. Later on I have a powershell .NET activity that uses this subscribed variable from the previous activity.

But how would I handle the possibility that someone may type an apostrophe or a quote character in the description?

I first spotted this with a test I am doing "Andrew's Test" which of course the script failed when assigning that variable within single quotes. I resolved that by changing the single quotes in the script variable assignment to double quotes.

But thinking about this, this is now just going to fail if someone has a double quote, for the same reason.

So, the correct way would be to handle this properly regardless.

If I am doing something like this...

$snDescription = "{SUBSCRIBEDVARIABLEID}"

How can I capture within that if there are single or double quotes and escape them before assigning? Would I just have to do like...

"{SUBSCRIBEDVARIABLEID}".Replace(""", """") - I know this is wrong, but is the idea right? Or if not, how could I do this?

Thanks

Andrew

msc-orchestrator
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndrewPerry-3419 avatar image
0 Votes"
AndrewPerry-3419 answered

Just wanted to come back on this.

The resolution for me was to use HERE-Strings in the script around the published data.

Thanks to Chris who also seems to have had the exact same issue...

https://www.concurrency.com/blog/w/using-here-strings-in-an-orchestrator-powershell-s


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

StefanHorz avatar image
1 Vote"
StefanHorz answered

Yes,
just use:
$snDescription = @'
{subscribed Variable}
'@

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.