cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1593
Views
20
Helpful
4
Replies

Add returned row data to REST call

chad_meyer
Level 1
Level 1

Hey everyone,

 

I am working on a CVP application that will return results from a SQL query and then send the returned row result(s) to an API.  The query is working as expected returning the following XML:

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Results>
<Row><SK_ID>5124</SK_ID></Row>
<Row><SK_ID>5315</SK_ID></Row>
</Results>

I am needing the results of each "SK_ID" entry to be fed into the following API:

 

<refURLs>
    <refURL>/unifiedconfig/config/agent/5124</refURL>
    <refURL>/unifiedconfig/config/agent/5135</refURL>
  </refURLs>

There may be varying results per query and won't be a set returned number every time.  I have a local variable set to parse XML via XPath but not sure where to go from there.  XPath is as follows:

 

importPackage(com.audium.server.cvpUtil);
var xml = {Data.Element.Agent Skill Lookup.resultSet};
var ctr = {Data.Element.ctRows.count};
var path = "/Results/Row[" + ctr + "]/SK_ID";
XPathUtil.eval(xml , path);

Any help would be appreciated. 

 

Chad

 

4 Replies 4

Quigath
Spotlight
Spotlight

For anything like this, that's more complicated than simple logic, I like to make a custom Java node and put all of my data processing logic in that class.

So which part do you need help with: setting up the java class, the logic, or integrating?

Thank you for the response @Quigath.  I am by no means a Java expert so would be hesitant in developing any custom classes (honestly have no clue where to start on that).  From a support perspective if something were to break I would also not have the know how to support/troubleshoot it.  If this would be the only solution I can certainly give it a go, however would not be my first option.  Can you advise why this method would be the best?  What does this class do that the built in elements could not?      

Quigath
Spotlight
Spotlight

I come from a Java/programming background so I suppose it's the first thing I think of. If there's any sort of data processing to do, it's much easier for me in plain java code rather than trying to get the gui and javascript to do the job instead.

From a software development perspective, having separate Java classes makes them easier to test and organize in source control too. The ones from Call Studio are harder to get a handle on.

Call Studio nodes are just specific Java class objects behind the scenes.

I tried to do almost exactly what you're trying to do: parse xml and send data to a webservice. I assumed that since it's what Call Studio provides that it must, somehow, be a better option. Usually, it isn't. Here I am several years later, still developing CS applications; now though, I assume that every project will be a mix of built-in and custom java nodes.

Unless there is a better way to do this I was able to get this working by the following call flow:

callflow.png

Here are the steps:

  • (DB_AgentLookup) SQL query returns results saved in <dbname>.xml_resultset
  • (ctRows) Counter with increment setting of 1 (starting at 0)
  • (ParseResults) Xpath that evaluates the xml_resultset element and the results path that auto increments the counter
  • (REST POST) API POST to webservice
  • (CTR Less than ReturnedResults) Run through all results and end when complete

If anyone has a better way to do this I would be interested in learning.  Note this is not the final call flow and will be tweaking to pass ICM variables for a more dymanic SQL query.

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: