Expand my Community achievements bar.

SOLVED

XML Data in Text Field Issue

Avatar

Former Community Member

LC ES 8.2.1.3

I have a web service that outputs XML data and Designer calls the webservice and the XML data populates a text field.  This works fine.

My problem is getting the data out of the text field to populate different fields in my form.  I have done many searches and have tried many different things but still can't get the data out.  I have made sure my form is dynamic xml.

Here is the last thing I have tried:

-------Begin Code -----------

Placed in testData:Intialize and the connectionSet is placed in Page1:Initialize.

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

var subNames = XMLData.applyXPath(myXML, "//Subordinates/Subordinate/full_name");

if (subNames == null) {
//no data
} else if (subNames.length == null) {
  //not array, just a single value
  topmostSubform.Page2.testData.addItem(subName.value);
  } else {
   for (var i = 0; i < subNames.length; i++) {
    topmostSubform.Page2.testData.addItem(subName.item(i).value);
    } 
   }

-------End Code -----------

I have been working on this for 3 days and still can't get it to work.  The closest I have come is output in my testData text field that said "Object23485968".

Thank you in advance for your help

John

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Forgot the lca file

Paul

View solution in original post

18 Replies

Avatar

Former Community Member

You will not be able to bind to that data as the structure is not know at render time. You can load that XML into the data dom then parse and place the data in the fields yourself (by parse I mean manipulate the Dom to give you back the value of a node).  There is a fair amount of coding involved. I have included a sample if you are interested. In my case I am populating a dropdown with the returned values.

Hope that helps

Paul

Avatar

Former Community Member

I must be missing something somewhere becuause I couldn't get it to work.  Here is the xml that I am getting back when I invoke the CFC from within Workbench.  This data is assigned to an XML type varialbe called 'xmlOutput'.  I then create a data connection in my form to the service I created in Workbench and bind the return data to a text field (with multiple lines).  When I bind the data I have the option to choose "document" or "element".  Element doesn't return anything, unless I am doing something wrong, so I have to choose Document. 

With the xmlOutput below I do get more than one subordinate returned.  I only showed one for simplicity.

------------Begin xmlOutput --------------  (Yes, I am getting all of these empty lines in my output)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://livecycle" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:getSubordinatesResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <getSubordinatesReturn xsi:type="xsd:string"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<subordinates>

    <subordinate>
       
       
       
        <cost_center_code>123456</cost_center_code>
       
       
       
        <cost_center_description>Business</cost_center_description>
       
       
       
        <department_code>99</department_code>
       
       
       
        <department_description>Information Technology</department_description>
       
       
       
        <department_head_emp_id>987654</department_head_emp_id>
       
       
       
        <employee_id>456789</employee_id>
       
       
       
        <first_name>John</first_name>
       
       
       
        <full_name>Public, John</full_name>
       
       
       
        <hourly_rate>5.350</hourly_rate>
       
       
       
        <job_code>PMBAPP</job_code>
       
       
       
        <job_title>Business</job_title>
       
       
       
        <last_name>Public</last_name>
       
       
       
        <lives_in_state>AK</lives_in_state>
       
       
       
        <location_code>ANCH</location_code>
       
       
       
        <location_description>Anchorage</location_description>
       
       
       
        <network_user_id>JPublic</network_user_id>
       
       
       
        <pay_group_code>KMH</pay_group_code>
       
       
       
        <rate_type_code>S</rate_type_code>
       
       
       
        <reports_to>789123</reports_to>
       
       
       
        <territory_code/>
       
       
       
        <tier>1</tier>
       
    </subordinate>

</subordinates

------------End xmlOutput --------------  (Yes, I am getting all of these empty lines in my output)

I am really at a loss on how to get this data into my form.

Thanks,

John

Avatar

Former Community Member

I am not sure I follow where you get the option to bind to document or element. You are getting the entire soap envelope into your variable. You may want to change your variable to a string instead of XML for transport. I would expect to bind the outputXML (which shoudl be defined as an output var in your process) to the field on your form directly. There are no options at that point. Then once you have the xml in the field you can load it into the DOM. Here is a sample where I query the user database and populate a dropdown. If you load up the LCA file that is licluded you can see how I achieve this.

Paul

Avatar

Correct answer by
Former Community Member

Forgot the lca file

Paul

Avatar

Former Community Member

Paul,

This worked perfect.  Thank you.

I have one more question.

I have assigned the full_name and employee_id to the dropdown list and am able to extract the employee id for use in another field whenever a selection is made in the dropdown.

My problem is that I don't know how to access the rest of the data in the node for that person that is selected.

Any thoughts on how to get the number of the node that is selected in the dropdown?

Thanks,

John

Avatar

Former Community Member

I assume that the you need to look further into the XML to find the node referenced by the Name selected then get the children of that node. If so that is possible. Before we investigate how to do that let me know if my assumption is correct. It woudl be easier if I coudl see the XML .....I may even have time to build a sample. You can send the xml to LiveCycle8@gmail.com

Paul

Avatar

Former Community Member

The XML structure is the same as what I posted above.

Here is my code that I use to extract out the full_name and employee_id:

--------- Begin Code -------------

//Parse out XML from text field.

var myXML = XMLData.parse(xfa.resolveNode("topmostSubform.Page1.subformStatChngForm.subformEmployeeData.subformEmplChanges.txtXMLString").rawValue, false);

//Get the node count of subordinates for the For loop.
var nodeCount = myXML.Subordinates.nodes.length;

//Message box is just for debugging
xfa.host.messageBox("There are " + nodeCount + " nodes!");

//Loop through and add all the Full Name and Employee ID to the Dropdown List.  The Employee ID is used as an index.
if (nodeCount.value == -1) {
  //No direct reports
  xfa.host.messageBox("You do not have any direct reports...!");
  } else if (nodeCount.value > 0) {
       //Not an array, just a single direct report
       topmostSubform.Page1.subformStatChngForm.subformEmployeeInfo.txtStatEmplName.addItem(myXML.Subordinates.nodes.item(0).nodes.item(3).value, myXML.Subordinates.nodes.item(0).nodes.item(0).value);
       } else {
           for(var i=0; i<nodeCount; i++){
                try {
                      topmostSubform.Page1.subformStatChngForm.subformEmployeeInfo.txtStatEmplName.addItem(myXML.Subordinates.nodes.item(i).nodes.item(3).value, myXML.Subordinates.nodes.item(i).nodes.item(0).value);
                     }
                     catch(e){}
            }
}

--------- End Code -------------

Thanks!

John

Avatar

Level 10

John,

     Here is a way I did in the past..

    

     //Execute the webservice..

     xfa.connectionSet.SubmitWebService.execute(0);

     //Loading the XML to data DOM
     xfa.data.loadXML(STSTripInfo.Page1.Subform13.VAR_String.rawValue);
 

     //Going thru the loop to find out the tags that are needed using the nodes.length
     for(var i=0;i<xfa.data.nodes.length;i++){

          if(xfa.data.nodes.item(i).name.toUpperCase()=="MESSAGE"){

          //Do processing here

          }
     }

Hope this gives some idea..

Thanks

Srini

Avatar

Former Community Member

I can access the nodes but what I need to do is when a user makes a selection in the dropdown list and selects an employee's name, I need to get the rest of the data from the node associated with that employee. If I could get the number of the node that is selected when the user selects the employee then I can work it out from there, but I can't seem to.

Thanks,

John

Avatar

Former Community Member

Is there a correlation between the position of the user in the DDlist and the position of the user in the xml file? If so then you could use the DDlist.selectedIndex to get you the position of the user. If that is not available then you could write a for loop that will search through each subordinate. employeeName field until you find the one your want.

Paul

Avatar

Former Community Member

Paul,

Actually there is. I will try that and let you know.

Thank you for your help!

John

Avatar

Former Community Member

I tried it and it didn't work. I was giving random numbers that didn't correspond to its place in the xml structure.

Thanks,

John

Avatar

Former Community Member

Remember that the DDList is 0 based and the other is 1 based (if that helps)....also the correlation is to the x instance of the node.

Paul

Avatar

Former Community Member

This is where I am having my problem. Creating a loop to search through the all of the nodes.

John

Avatar

Former Community Member

Are there multiple subordinate nodes (your example only shows one) ......and you have to find the one with the name that was pulled from the DDlist?

paul

Avatar

Former Community Member

Ok I took your xml and added two additional subordinate nodes and wrote a sample that shows how to get to those nodes. See the attached.

paul

Avatar

Former Community Member

Paul,

Here is what I was trying to do. I tested it in the exit event of my dropdown list and it worked perfect.  It returned the subordinate node placement in the xml.

-------------Begin Code --------------

//Parse my xml from the text field.

var myXML = XMLData.parse(topmostSubform.Page1.subformStatChngForm.subformEmployeeData.subformEmplChanges.txtXMLString.rawValue, false);

//Since I already stored the node length in another field on the initialize event of my subform I was able to use that for the For loop.

for(var i=0; i<topmostSubform.Page1.subformStatChngForm.subformEmployeeData.subformEmplChanges.sNodeCount.rawValue; i++) {
       if (xfa.resolveNode("topmostSubform.Page1.subformStatChngForm.subformEmployeeInfo.txtStatEmplID").rawValue == myXML.Subordinates.nodes.item(i).nodes.item(0).value)
           {
                 xfa.host.messageBox("Selected Index = " + i);
                 break;
           }
}

-------------End Code --------------

Thank you for all of your help!!  I may need to start a blog to pass this along to others.

Thanks,

John

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----