Hi All,
I am getting the response from exec procedure like below:
[success:true,error:,parameters:[BOOKS_CURSOR:[quantity:23,author:Collectif,price:3.74,title:Peppa Pig: Fun at the Fair]; [quantity:7,author:Judith Simanovsky,price:4.99,title:Panda Goes to the Olympics]],result:]
But I need to save the values of BOOKS_CURSOR in Books CDT which has quantity, author,price & title fields. Can you please guide how can I do it?
Thanks
Discussion posts and replies are publicly visible
Look into the cast() function.Something like this should work:
cast( typeof(type!Typeofyourcdt), local!value)
It should be formatted as below, and your label names should match your CDT field names:
cast( typeof({type!Book()}), {{quantity:23,author:"Collectif",price:3.74,title:"Peppa Pig: Fun at the Fair"}, {quantity:7,author:"Judith Simanovsky",price:4.99,title:"Panda Goes to the Olympics"}})
Let me know if that works for you.
I believe you need to use the extract() function. I suggest making a modular expression rule specifically to handle this conversion, for ease of access and updating in the future. I've written one previously to translate the results of the "getprocessmodeldetailsbyuuid()" plug-in function into dictionary, and it works fairly well.
The following code assumes you will create it as an expression rule and the ri! will be the string (and that if at any point you want to do multiple book strings, you'll apply() this rule over the list).
with( local!quantity: extract(ri!rawText, "quantity:", ",author"), local!author: extract(ri!rawText, "author:", ",price"), local!price: extract(ri!rawText, "price:", ",title"), local!title: extract(ri!rawText, "title:", "]"), { author: local!author, title: local!title, quantity: local!quantity, price: local!price } )
In this example I establish each value as its own with() variable before wrapping up everything in a dictionary to be returned at the end. This might seem slightly overcomplicated but separating the processing in such a way helps if you ever decide the dictionary names should be different, or if one particular field value needs pre-processing before being returned, etc.