Genesys CTI User Forum
Genesys CTI User Forum => Genesys CTI Technical Discussion => Topic started by: clemouk on February 28, 2012, 07:14:19 PM
-
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
-
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.
-
Did u get answer for this post, i am facing the same issue. Please assist me on this if you can
-
[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.
-
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.
-
Thank you very much for this instruction......
-
Can You please explain it in detail
-
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
-
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.
-
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