Freshservice - Adding user to AD with apostrophe in display name fails

Hi All,
We are using the on prem AD orchestrator and the out of the box ‘create ad user’ script. When attempting to create a user with an apostrophie in their name it fails. Gives ‘error: The display_name contains a single quote (’).
Example: Johnny O’Test
AD itself has no such restriction and the user can be created manually with no problem.
Any ideas please
Colin

Do you use the orchestration app? It use powershell commands on the server.
Found this escaping - Can I use a single quote in a PowerShell ‘string’? - Stack Overflow

Not sure if it going to help but if it works with 2 ’ you could maybe do it this way.
{{ placeholdername | replace: "'","''" }}
It will replace 1 single quotes with 2 single quotes

Hi Daniel, Thanks for the tip. Unfortunately the replace worked fine but still generated the error.
From the Orchestrator log:
Sending message to BrokerMQ:{“level”:0,“message”:“Setting DisplayName as Jennie O’'Test”
“Error: The display_name contains a single quote (') .”

I’m not sure if FreshService is passing the string in single or double quotes.
If single quotes then the escape should work. If double quotes the escape should not be required.
Colin

Hi Daniel. And anyone else who may be interested.
I have resolved this issue. It was being caused by the Freshworks out of the box scripts. They actively throw errors when detecting user names with single quotes in them.
I have rewritten their scripts to handle single quotes correctly.
Not sure why they would have done this other than to save a couple of lines of code and risk doing it properly.
Not impressed!
Perhaps the script author: Akash Hirve would care to comment?
Colin

If you don’t mind sharing, where are the out of box scripts visible? And how did you rewrite them exactly? Not the code, I mean from what interface to the product? I don’t see any .ps* files on the Orchestration server where I would have guessed so I’m kind of stumped on how this is possible, without just writing the scripts froim scratch.

The scripts I edited were:

Create_user.js
Add_user_to_group.js

Get_user.js
Get_user_with_upn.js

These are located here on your orchestration server:

C:\Program Files\Freshworks\Orchestration Server\osr\flintbox\flint-util\ad-winrm\operations\

            // Escape single quotes in name (replace ' with '')

            name = name.replace(/'/g, "''");

Hope that helps

Hey, thanks for this! I didn’t even think to look for js files.

While looking around I stumbled upon what I think is a pretty significant bug in the create_user.js file. Line 43 there is ‘comand’ where there should be ‘command’ - can you check what you have and tell me if you have the same mistake? Or anyone else who reads this.

I submitted a support ticket but I don’t know how long that will take and I’m curious if anyone in the community has the same version. The comments in my version of this file indicate it was last updated in 2022, FWIW.