How can I rectify a string that begins and ends with a backtick, while ensuring that the contents of the evaluated expression also contain backticks?

const abcd = `[@parent.[#(?object=activity::criteria=typeid=76273 AND tbl_1770949.valuestr="1"::orderby=tbl_1770943.valuestr ASC){"userid":"$txtUserid$","organisations":"$rdOrganisations$","oversightGroupRole":"$cmbOversightRole$","oversightGroupMemberName":"$txtOversightPrefix$ $txtOversightFirstName$ $txtOversightSurname$","oversightGroupType":"$cmbOversightGroupType$"},#]@]`;

//Please note the statment 
[@parent.[#(?object=activity::criteria=typeid=76273 AND tbl_1770949.valuestr="1"::orderby=tbl_1770943.valuestr ASC){"userid":"$txtUserid$","organisations":"$rdOrganisations$","oversightGroupRole":"$cmbOversightRole$","oversightGroupMemberName":"$txtOversightPrefix$ $txtOversightFirstName$ $txtOversightSurname$","oversightGroupType":"$cmbOversightGroupType$"},#]@]
 evaluates the string in the format below-e.g
[{
    "userid": "88664753",
    "organisations": "Liverpool Heart and Chest Hospital NHS Foundation Trust*NIHR CRN Northwest Coast*University of Liverpool*",
    "oversightGroupRole": "Member",
    "oversightGroupMemberName": "Mr abcd",
    "oversightGroupType": "Steering Committee"
}, {
    "userid": "",
    "organisations": "University of Liverpool*",
    "oversightGroupRole": "Member",
    "oversightGroupMemberName": "Professor ccc",
    "oversightGroupType": "Steering Committee"
}, ]

My statement fails if any one the properties(userid,organisations etc) values contains backtik.
How can I fix that. How can I rectify an evaluated expression string that begins and ends with a backtick, while ensuring that the contents of the evaluated expression also contain backticks?

You can escape backticks in the content by preceding them with a backslash. This should allow you to use backticks in the middle of a template literal.

4 Likes