cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
248
Views
2
Helpful
1
Replies

CVP Call Studio-Looping through XML

Tanner.Zesiger
Level 1
Level 1

Hello,

I'm trying to write an application in Call Studio that takes the output of a Finesse Get-Team call and returns the loginId of a user based on an extension and team ID passed in by ICM.

https://developer.cisco.com/docs/finesse/team/#team

I know I can use XpathUtil to check the value of properties, but I'm stuck on how to loop through the multiple User entries that are nested in the Team/Users response in the results.

https://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cust_contact/contact_center/customer_voice_portal/12-6-2/user/guide/ccvp_b_1262-user-guide-for-cisco-unified-cvp-vxml-server-and-call-studio/ccvp_b_1251-user-guide-for-cisco-unified-cvp-vxml-server-...

I'm not sure what the limitations of the Set Value element's Settings section is where the XPath Expression example in the documentation are. Based on the example linked below, I was able to piece how to use the Rest Client in Call Studio to query data and pull from the response with XPath.
https://community.cisco.com/t5/contact-center/sample-cvp-call-studio-using-rest-element/m-p/3463474#M2310

The problem is that output from the Get-Team API in Finesse returns multiple User entries in Users.

I've gotten as far as assuming I need to create a foreach loop something like the below 

 

importPackage(com.audium.server.cvpUtil);
//REST client output
var xml= {Data.Element.Finesse.response_body};

//pseudo code foreach loop
foreach (XpathUtil.eval(xml,"/Team/Users") => {
  //check the current User's Extension value against what ICM provided
  if (XpathUtil.eval(xml,"/Team/Users/User/Extension") == Data.Session.Extension) {
    //write the matching user's loginId to the element's variable
    XpathUtil.eval(xml,"/Team/Users/User/loginId");
  }
});

 


Any feedback, insight, or alternative options are welcome!

1 Accepted Solution

Accepted Solutions

janinegraves
Spotlight
Spotlight

You don't need to loop.

XPath expressions allow filters to select row(s) of an array based on a value of a child tag of the array.

So if you want the loginId for the entry where the /Team/users/User[#]/extension='1001002' then you can use this XPath expression: var path = "/Team/users/User[extension='1001002']/loginId"

In your case, concatenate the Session Data into the path (this is tricky because you must use the + sign to concatenate the Session Data variable into the literal path expression:
var path = "/Team/users/User[extension='" + {Data.Session.Extension} + "']/loginId"

You should probably use the count function of arrays in XPath to determine whether or not the Extension was contained in the XML. And if not, then assign something like "NA" into the Local Variable. Then follow with a Decision element and check if the value of the Local Variable created equals the string NA.

Use this in the SetValue element:

importPackage(com.audium.server.cvpUtil)
var xml= {Data.Element.Finesse.response_body};

var path1 = "/Team/users/User[extension='" +{Data.Session.Extension}+ "']"
var numResults = XpathUtil.eval(xml, path1)

if(numResults>0){
var path2 = "/Team/users/User[extension='" +{Data.Session.Extension}+ "']/loginId"
XpathUtil.eval(xml, path2)
} else {
"NA"
}

View solution in original post

1 Reply 1

janinegraves
Spotlight
Spotlight

You don't need to loop.

XPath expressions allow filters to select row(s) of an array based on a value of a child tag of the array.

So if you want the loginId for the entry where the /Team/users/User[#]/extension='1001002' then you can use this XPath expression: var path = "/Team/users/User[extension='1001002']/loginId"

In your case, concatenate the Session Data into the path (this is tricky because you must use the + sign to concatenate the Session Data variable into the literal path expression:
var path = "/Team/users/User[extension='" + {Data.Session.Extension} + "']/loginId"

You should probably use the count function of arrays in XPath to determine whether or not the Extension was contained in the XML. And if not, then assign something like "NA" into the Local Variable. Then follow with a Decision element and check if the value of the Local Variable created equals the string NA.

Use this in the SetValue element:

importPackage(com.audium.server.cvpUtil)
var xml= {Data.Element.Finesse.response_body};

var path1 = "/Team/users/User[extension='" +{Data.Session.Extension}+ "']"
var numResults = XpathUtil.eval(xml, path1)

if(numResults>0){
var path2 = "/Team/users/User[extension='" +{Data.Session.Extension}+ "']/loginId"
XpathUtil.eval(xml, path2)
} else {
"NA"
}