" /> Composer 8.1 - Passing JSON Objects to Backend ASP.net file - Genesys CTI User Forum

Author Topic: Composer 8.1 - Passing JSON Objects to Backend ASP.net file  (Read 9016 times)

Offline clemouk

  • Newbie
  • *
  • Posts: 39
  • Karma: 0
Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« on: February 28, 2012, 07:14:19 PM »
Advertisement

This may not be the best forum for this post, but I thought I'd see if anyone has experienced any issues of a similar nature. Basically, I have a GVP application that makes a call via a "WebRequest Block" to a web service that returns a collection of Key/Value pairs. The result of the block is captured in a variable called "WebRequestResult" and can be viewed as a JSON object at runtime in the debugger.

I then use a "Backend Request Block" to call an ".aspx" page and send the variable "WebRequestResult" as "UserKeys".

What I want, is to pass this variable as-is (by that I mean a JSON object) to a backend ASP.Net page for further processing. This is where I encounter the problem, the variable gets passed as a parameter via the Hashtable into the function PerformLogic() but I am struggling to restore the parameter as a JSON object.

The three "inputX" statements below are what I've tried so far, with the result at the end. Has anyone else had problems passing parameters into backend ASP.Net files? Is there a better way of doing this?

[code]public override JObject PerformLogic(JObject state, Hashtable additionalParams)
    {

        object input1 = additionalParams["UserKeys"]; //input1 = "[object]" - no error

        string input2 = (string)additionalParams["UserKeys"]; //input2 = "[object]" - no error

        JObject input3 = (JObject)additionalParams["UserKeys"];  //input3 - cannot convert System.String to JObject, InvalidCastException

        JObject result = new JObject(new JProperty("VParameters", input1));
                 
        // send back data to gvp app
    return result;
    }[/code]

Thanks,
Lee

Offline René

  • Administrator
  • Hero Member
  • *****
  • Posts: 1832
  • Karma: 62
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #1 on: March 01, 2012, 07:54:44 AM »
Hi Lee,

I think that you should convert JSON object to string (using stringify method) to pass it as input variable to back end. Later, you can convert it back to JSON object in your code.

R.

Offline vijaysenz_genesys

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #2 on: April 25, 2012, 07:32:12 AM »
Did u get answer for this post, i am facing the same issue. Please assist me on this if you can

Offline clemouk

  • Newbie
  • *
  • Posts: 39
  • Karma: 0
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #3 on: May 01, 2012, 03:18:47 PM »
[quote author=vijaysenz_genesys link=topic=6963.msg30604#msg30604 date=1335339132]
Did u get answer for this post, i am facing the same issue. Please assist me on this if you can
[/quote]

No we didn't find a solution to this problem, due to the tight schedules we didn't have the opportunity to play around either so as the number of KVP's are fixed in our environment, they are now hardcoded into the ASPX page. I hope to come back to this at some point as I would really like to improve this and have the KVP's completely dynamic and database driven instead of included in the code.

Offline René

  • Administrator
  • Hero Member
  • *****
  • Posts: 1832
  • Karma: 62
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #4 on: May 03, 2012, 03:11:19 PM »
Hi guys,

I did quick test when JSON returned by WebRequest block was serialized to string format and passed as parameter to BackEnd block and it works - I was able to restore JSON object in BackEnd block (ASPX page) and work with that object.

Let me know if you need more details.

R.

Offline nick561

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #5 on: May 08, 2012, 04:41:20 AM »
Thank you very much for this instruction......

Offline vijaysenz_genesys

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #6 on: May 08, 2012, 11:36:29 AM »
Can You please explain it in detail

Offline clemouk

  • Newbie
  • *
  • Posts: 39
  • Karma: 0
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #7 on: May 09, 2012, 08:46:58 AM »
Hi Rene,

When I tried this previously, I received the value "[object object]" in my backend ASPX code so I couldn't do anything with this.

I would be grateful if you could please provide a quick example?

I'll also go back and look at what I did and see if I can replicate the problem I was having before.

Thanks,
Lee

Offline René

  • Administrator
  • Hero Member
  • *****
  • Posts: 1832
  • Karma: 62
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #8 on: May 09, 2012, 10:04:45 AM »
Hi guys,

Let me describe solution that works for me :)

1/ Let's have JSON object (variable objJSON) created manually or returned by Composer block

2/ Object must be serialized (converted to string) before it can be passed as parameter to BackEnd block. JSON object provides function - stringify - for this
[code]variable strJSON = JSON.stringify(objJSON);[/code]

3/ Now you can pass strJSON variable as input parameter (ParamName1) to BackEnd (ASPX page)

4/ It's necessary to deserialize JSON object before working with it (ASPX page)
[code]public override JObject PerformLogic(JObject state, Hashtable additionalParams)
{
    JObject result = new JObject();

    string param1 = (string)additionalParams["ParamName1"];

    if (param1.Trim().Length > 0)
    {
        JObject param = JObject.Parse(param1);
    }

    // add your code here

    return result;
}[/code]

That's all. I tested it with GVP 8.1.4 (app was created using Composer 8.1)

R.

Offline gstkein

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 4
Re: Composer 8.1 - Passing JSON Objects to Backend ASP.net file
« Reply #9 on: June 08, 2016, 07:57:03 PM »
One more thing, if a parameter must contain ; character the hay to write it is to encode it as %3B

for example
user_data=loginId%3BclientNumber;ucid=123

would produce 2 variables:
user_data=loginId;clientNumber
ucid=123