Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Binding web service to multiple drop-down fields.

Avatar

Level 8

I am getting alogn quite well using Web Services with Adobe XFA Forms. I was able to bind very complex web services results to dynamic PDF Forms.

I was also able to bind Drop-Down Items to a web service.

I still need little help though.

I have 2 Drop-Down Fields:

Hijri Year


Hijri Month

They are retrieved by Web Service developed over SAP Systems.

The web service will return a nested XML Structure of Hijri Year Array of Items, where each Year Item, will have nested array of months item.

When I click on the button to execute the Web Service, the Year Drop Down is populated. So now how to populate the Month Drop-Down Items ?

It is a bit tricky, and I cannot figure out what to do.

Please help.

Tarek.

8 Replies

Avatar

Level 8
I have posted the image of the DataConnection and Form Layout to make it more clear:

http://bit.ly/9CFimU

http://bit.ly/9CFimU

I noticed, if I bind the Months Drop-Down Items, I will get the list of all months of all the years, which is funny. I need to get only the list of the months of the selected year.

Appreciate your help.

Tarek.

Avatar

Former Community Member

You won't be able to bind directly. You will have to bind the returned output to a field then load the xml into the data dom, then bind the fields to the data through script. I have included a sample that does this to give you an idea.

Paul

Avatar

Level 8

Well, I was almost about to do that with very little coding, but looks like it is not possible. I seems that I have to bind the XML to the dorp-down manually.

I am using Stefan Web Service Per-Processor model. I am capturing the web service reulst, and loading the node I want to xfd.datasets.data.

I am doing something like this:

Sample XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<AttendancePeriod>
   <item>
      <Year>1430</Year>
      <Periods>
         <item>01</item>
         <item>02</item>
         <item>03</item>
         <item>04</item>
         <item>05</item>
         <item>06</item>
         <item>07</item>
         <item>08</item>
         <item>09</item>
         <item>10</item>
         <item>11</item>
         <item>12</item>
      </Periods>
   </item>
   <item>
      <Year>1431</Year>
      <Periods>
         <item>01</item>
         <item>02</item>
         <item>03</item>
         <item>04</item>
         <item>05</item>
         <item>06</item>
         <item>07</item>
         <item>08</item>
         <item>09</item>
      </Periods>
   </item>
</AttendancePeriod>
</root>

DataConnection Post Execute Event:

var rootXml = null;
var soapFault = null;
if (xfa.event.soapFaultCode)
soapFault = {code:xfa.event.soapFaultCode, message:xfa.event.soapFaultString};
else
rootXml = xfa.datasets.connectionData.DataConnection.Body;

preProcessor.processResponse(rootXml, soapFault);

The Response Processor function:
/**
* Called after the web service response has been received.
* @param rootXml XML node which is the root of the web service response XML data. Null if a fault occurred.
* @param soapFault Object with 'code' and 'message' properties if a fault occurred; null otherwise.
*/
function processResponse(rootXml, soapFault)
{
console.clear();
if (rootXml)
{
  var AttendPeriod = rootXml.GetAttendancePeriodsResponse.AttendancePeriod;
  xfa.datasets.data.root.nodes.append(AttendPeriod);

  xfa.form.remerge();
  console.println(AttendPeriod.saveXML());
}
else if (soapFault)
{
  console.println("Error = ");
  console.println("Fault code: " + soapFault.code);
  console.println("Fault message: " + soapFault.message);
}
console.show();
}

Then, I will bind the drop-down list to the XML.

The above code is working fine, but the only problem is xfa.form.remerge(), which will clear all other fields, I am not sure why ?

Seems I have to use a loop to bind the list items one by one, right ?!!

Tarek.

Avatar

Level 8

This is the final version of the script, in case someone else will find it useful:


function processResponse(rootXml, soapFault)
{
console.clear();
if (rootXml)
{
  var AttendPeriod = rootXml.GetAttendancePeriodsResponse.AttendancePeriod;
  if (!getPeriodDataNode()) {
   xfa.data.root.nodes.append(AttendPeriod);
   populateYearDDL(Body.Criteria.DDL_HijraYear, Body.Criteria.DDL_Month);
  }
 
}
else if (soapFault)
{
  console.println("Error = ");
  console.println("Fault code: " + soapFault.code);
  console.println("Fault message: " + soapFault.message);
  console.show();
}
}

function getPeriodDataNode() {
var dataAttendPeriod = xfa.data.root.resolveNode("AttendancePeriod");
return dataAttendPeriod;
}

function removePeriodDataNode() {
var theNode = getPeriodDataNode();
if (theNode) {
  xfa.data.root.nodes.remove(theNode);
}
populateYearDDL(Body.Criteria.DDL_HijraYear, Body.Criteria.DDL_Month); // clear both DDL
}

function populateYearDDL(theYearDDL, theMonthDDL) {
var yearItems = xfa.data.root.resolveNodes("AttendancePeriod.*.Year[*]");
theYearDDL.clearItems();
for (var i=0; i < yearItems.length; i++) {
  //console.println("Year Item = " + yearItems.item(i).value);
  theYearDDL.addItem(yearItems.item(i).value);
}
theYearDDL.selectedIndex = -1;
theMonthDDL.clearItems();
theMonthDDL.selectedIndex = -1;
}

function populateMonthDDL(theYearKey, theMonthDDL) {
console.clear();
var monthItems = xfa.data.root.resolveNodes("AttendancePeriod.*.(Year.value=='"+theYearKey+"')..item[*]");
theMonthDDL.clearItems();
for (var i=0; i < monthItems.length; i++) {
  theMonthDDL.addItem(monthItems.item(i).value);
}
theMonthDDL.selectedIndex = -1;
}

Validate Event for Input Parameter required for the Web Service:

if (this.rawValue != "" && this.rawValue != null) {
xfa.connectionSet.DataConnection.execute(0);
} else {
preProcessor.populateYearDDL(Body.Criteria.DDL_HijraYear, Body.Criteria.DDL_Month);
}

Change Event of the Hijri Year DD:

preProcessor.populateMonthDDL(xfa.event.newText, DDL_Month);

Avatar

Level 7

Paul - I am trying to use the code from the pdf file and it doesn't seem to work as a function. The two parameters except xNode seem to work.

function fill_ddl(ddlField,wsdlNode,xNode)

{

page1.flags.invokeBtn.execEvent('click');

var myXML = XMLData.parse(wsdlNode.rawValue, false);

var nodeCount = myXML.form1.nodes.length;

for (i=0;i<nodeCount;i++)

{

ddlField.addItem(myXML.form1.nodes.item(i).xNode.value);

}

}

And, I use the following parameters to call the function.

func_lib.fill_ddl(page1.header.home_office,page1.flags.home_office_string,home_office);

Aditya

Avatar

Level 7

Nothing... the code just doesn't work... I don't know what is with the third parameter. Does it work for you?

Aditya