Solved

Expression builder, String output with double quotes?


Userlevel 3
Badge +7

Hi

I have issues with expression builder that I hope someone can help me with. 

I have a string that I would like transform slightly by replacing a specific part of it by using the “Replace” function. This works good but I have issues with the output.
The input string includes double quote characters and the output string should have these intact but for some reason the output string transforms the double quotes to single quotes. Is there a way to work around this issue?

My input string looks similar to this:
\“role_id\”:52000143029,\”assignment_scope\”:\”member_groups\”

And after replacing “member_groups” with “entire_helpdesk” the result becomes like this:
‘role_id’:52000143029,’assignment_scope’:’entire_helpdesk’

 

See example screenshot from a simple expression node with this issue.

 

icon

Best answer by Daniel Söderlund 8 March 2023, 10:09

View original

13 replies

Userlevel 7
Badge +13

You could use replace – Liquid template language (shopify.github.io) if you are going to use it in API payload you can try that. 

Userlevel 7
Badge +13

So you use {{placeholder | replace: “member_groups” , “entire_helpdesk”}}

Userlevel 7
Badge +13

But where do you get that inputstring from ? 

It looks like the output you see the Execution Logs and it’s not what you get from the web request node and the parser node.Then the placeholder will give you something like this. 

“role_id”:52000143029,”assignment_scope”:”member_groups”

Userlevel 7
Badge +13

If you just like to fix your output you could use liquidfilter replace “’”, ‘”’ 
double quote singel quote double quote, singel quote ​​​​​​​double quote singel quote 
I haven’t tested it. 

Userlevel 3
Badge +7

Hi,

I get the input from using Get Agents in a web request. I have pasted the output from the first “Get” web request here below as well as the output from the Expression node where I have used the replace function.

See how the double quote turns in to a single quote.

 

 

I tried using the liquid language as you proposed but get same result in a simple test, see below.

 

Userlevel 3
Badge +7

Perhaps I should explain what I want to achieve as well in case there are other ways to do it :)

I intend to have a service item where Agents can request “elevated access” in case they need to reach tickets that is “stuck” in groups where they do not have access and no one in that group is available to help due to time zone differences etc. So my idea is to temporarily adjust the scope for a specific role through a wfa.

Userlevel 6
Badge +10

Sounds silly, but rather than put the quotes in the expression, can you put the quotes in the get web request directly?

Userlevel 7
Badge +13

Perhaps I should explain what I want to achieve as well in case there are other ways to do it :)

I intend to have a service item where Agents can request “elevated access” in case they need to reach tickets that is “stuck” in groups where they do not have access and no one in that group is available to help due to time zone differences etc. So my idea is to temporarily adjust the scope for a specific role through a wfa.

Well then I would do something like this WR(GET) →  Parse → WR(PUT) using  Liquid filter 
payload: 

“roles”: {{root.agent.roles | replace: “member_groups”, “entire_helpdesk” }}

}

Timer 30 min 

WR(PUT)
payload: 

“roles”: {{root.agent.roles}}

}

Userlevel 7
Badge +13

Then the agent vill get full access for all roles but they will be returned after the timer node is done 

 

Userlevel 7
Badge +13

When I’m working with WR I add a condition node after it to check the return code, if it’s not 200 I add the respons and the payload to a private note. 

Userlevel 3
Badge +7

Yeah, that might work. It will however give the agent elevated access for all assigned roles though which is more than I wished for. But that is good enough in our current situation but might not be in the long run.

 

I used your example and it worked with one addition.

When using GET Agents command the result for each role in the array includes the line: ,"groups":null.

When using PUT Agents command the payload is rejecting that line strangely enough. So needed to filter that out in the payload to get it to work.

The final, and working, payload for updating the access is:

{
"roles":{{P1.root.agent.roles | replace: "member_groups", "entire_helpdesk" | replace: ',"groups":null',""}}
}

And to put it back after a timer node the code is similar.

{
"roles":{{P1.root.agent.roles | replace: ',"groups":null',""}}
}

 

Thanks for the help

Userlevel 7
Badge +13

I think you need to do dubble parse to get to the array of the roles. 

Userlevel 3
Badge +7

Well, I actually managed to get it to work for the targeted role now by adjusting the liquid filtering in the payload :)

The payload looking like this worked to update only the scope of one specific role:

{
"roles":{{P1.root.agent.roles | replace: '52000143029,"assignment_scope":"member_groups"', '52000143029,"assignment_scope":"entire_helpdesk"' | replace: ',"groups":null',""}}
}

Thanks again for the input

Reply