Skip to main content
Kinetic Community

Getting IDs and Values out of Simple Data Request Results

There may be cases where you need to work with the results returned from a Simple Data Request as something other than a table (see Populating a Table Using a Simple Data Request for instructions on that).

Usage

The following example code can be called as the callback for the simple data request:

  var connection=new KD.utils.Callback(parseSDR,alert); 

Example SDR Response

<result>​
<requestName>Get Approvals</requestName>
<errorMessage/>​
<record>​
<field id="SurveyCompletedDate"/>
<field id="Submitter">Demo</field>
<field id="SurveySentDate">04/22/2012 22:16:33</field>
<field id="CustomerSurveyID">KSR000000003003</field>
<field id="ValidationStatus">Approved (by Proxy)</field>
<field id="Last Name">Don</field>
<field id="First Name">Demo</field>
</record>
<record>​
<field id="SurveyCompletedDate">04/22/2012 22:17:16</field>
<field id="Submitter">Mary</field>
<field id="SurveySentDate">04/22/2012 22:16:37</field>
<field id="CustomerSurveyID">KSR000000003004</field>
<field id="ValidationStatus">Approved</field>
<field id="Last Name">Manager</field>
<field id="First Name">Mary</field>
</record>
​</result>

Example

 

function parseSDR(response) {
 /*retrieve the XML from the response and the results from the XML*/
 var xmldoc = response.responseXML;
 var resultsList = xmldoc.childNodes;
 
 /*retreive the field Nods out of the results*/
 var fields = resultsList[0].getElementsByTagName("field");

 /*set up variables*/
 var i=0;
 var detailsValue = "";
 var detailsId = "";
 
 /*step through all the fields*/
 for(i=0;i<fields.length;i++){
   var details = fields[i].childNodes;
   
   if (details.length >= 1 ) //check that this field contains values 
   {
     detailsValue = details[0].nodeValue;
     detailsId =  fields[i].attributes.getNamedItem("id").value;
     /* Now you have the value and ID to work with */
   }
 }
}

Example 2

The above example can have issues with certain versions of jquery or Internet Explorer (IE), so here is another example, which leverages some Kinetic Data javascript.

function parseSDR(response) {
/*retrieve the XML from the response and the results from the XML*/
var records=KD.utils.Action.getMultipleRequestRecords(response);
var len = records.length;

/*set up variables*/
var i=0;
var detailsValue = "";
var detailsId = "";

/*step through all the records*/
for(i=0;i<len;i++){
   var details = records[i].childNodes;
  
   /*step through each field*/
   for(var k=1;k<details.length;k=k+2) {
     detailsId =  details[k].id;
     detailsValue =  KD.utils.Action.getRequestValue(records[i], detailsId);
     /* Now you have the value and ID to work with */
   }
}
}