Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

Call Flow Designer CONCATENATE problem

Discussion in 'Call Flow Designer' started by Infinitel, Jun 5, 2017.

Thread Status:
Not open for further replies.
  1. Infinitel

    Joined:
    Jun 5, 2017
    Messages:
    2
    Likes Received:
    0
    Hello, I'm performing some test to integrate CFD with a JSON WebService and I've found some issues trying to compose the POST content.

    My web service expects something like:

    {"id":"x","caller":"xxxxxxxxxx"}

    To compose the json string on CFD I'm using CONCATENATE

    CONCATENATE( "{\"id\":\"" , session.callid , "\",\"caller\":\"" , session.ani , "\"}" )

    The CFD seems to interpret "\",\"caller\":\"" which should be a single entry as two entries (it seems to tokenize the entry using the comma that is inside the string). Using the Expression editor you can see it on a single line before saving (attached before.png) and splitted after saving. This seems to malform the sent json message.

    BEFORE:
    before.png

    AFTER:

    after.png

    I've tried to use stardard String concatenation from the c# expression editor but CFD reports that session is not accesible in this context at compile time. something like: "{\"id\":\"" + session.callid + "\",\"caller\":\"" +...

    Is there any way to escape comma character in the expression editor? Or is there any way to access session from the c# editor?

    Thanks.
     
  2. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,684
    Likes Received:
    131
    Hi @Infinitel,

    Thanks for reporting this, which seems to be a bug. We'll work to fix it in the next release.

    You have other options to achieve this:
    1) When the CFD converts the project to C# code, the variables are included in a Dictionary. You can use the following expression to access the variables from your C# expression:
    "{\"id\":\"" + variableMap["session.callid"].Value + "\",\"caller\":\"" + variableMap["session.ani"].Value + "\"}"

    2) Another possible way to do this could be using a Launch External Script component, invoking a method which receives 2 parameters: session.callid and session.ani. Your code could be the following:
    Code:
    namespace JsonHelper
    
    {
      public class JsonHelper
      {
        public string GenereateJSON(string callid, string ani)
        {
          return "{\"id\":\"" + callid + "\",\"caller\":\"" + ani + "\"}";
        }
      }
    }
    
    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Infinitel

    Joined:
    Jun 5, 2017
    Messages:
    2
    Likes Received:
    0
    Ok, that will solve the issue. :)

    Thanks for your help.
     
Thread Status:
Not open for further replies.