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.

web service for populating drop-down lists

Avatar

Former Community Member

Hello all

What's the best technique for generating a web service (as a short-lived process) so that I can use its response items for populating a drop-down list?

Right now I use just an object in my process : Query for multiple rows as XML. The only output variable of the process is a string that contains this:

<listaGiros>
    <giro>
        <idGiro type="int">1</idGiro>
        <nombreGiro type="varchar">ADMINISTRACION DE RENTAS</
nombreGiro>
    </giro>
    <giro>
        <idGiro type="int">2</idGiro>
        <nombreGiro type="varchar">CAFETERIA</nombreGiro>
    </giro>
</listaGiros>

My purpose is to use the dynamic binding properties of the drop-down, so that every giro node represents an item of the list (using a WSDL data connection pointing to my short-lived process). I want to avoid parsing the XML string.

How should I configure the output of the process?

21 Replies

Avatar

Former Community Member

The output is a single string of XML that represents the xml query. The tools can ot introspect into that xml ...they only see a single string. So you can bind the string to a single multiline field. Then load the xml that is put into that field into the data dom then manipulate the dom to poulate the ddlist. I have an example that you can load into your system to see it in action  if you want.

Paul

Avatar

Former Community Member

I would like to see your example, thank you.

But I still need to know what it takes to embed that XML as nodes of the webservice response (an enumeration, perhaps)

Avatar

Former Community Member

From the jdbc service teh output was a string variable. I made that an ouput and the wsdl now holds a string (that is in fact XML).

Attached is my sample ...complete with form and lca file that represents the process that I call. I am doing a search in the user DB, so enter in a char line s to search on and all users with an s in the name will be extracted.

Paul

Avatar

Former Community Member

Hello Paul,

Thanks for posting the helpful example. From your LCA of the LC Web service that you built, I try to use the JDBCService-Query for Multiple Rows instead of "LDAP Query to XML" but could not make it work right.

Can you please help on this.

Thanks in advance,

Han Dao

Avatar

Former Community Member

Are you getting the xml that represents the query back from the web service and is this showing up in th ehidden field? Can you elaborate on what is not working? There are many moving parts to this solution so you will have to check each part out individually.

Paul

Avatar

Former Community Member

Hi Paul,

Well, if I hard coded the name of the variable 'lookupString' like this query (select * from tableB where commonname  = 'JOHN SMITH' ) then I got some data when I test the query.  If I put the xpath in the query like (select * from tableB where commonname  = '{$ /process_data/@inputString $}' ) then it does not give me any data but it works if I use the  "Query for Single Row".

Thanks,

Han Dao

Avatar

Former Community Member

You shoudl be using a parameterized query .....there you can supply sample data as well as indicate which process var to use when the "real" query is run. A ? in the SQL statement indicates that this part will be replaced by a parameter identified in the table. The positional location of the ? indicates which param to use. Here is a screen shot for an example:

screen1.png

Note the checkmark that indicates that we will use a Parametrized query. Then the ? in the SQL statement gets replaced with the information in the table. When I click on the Test button the Test Value indicated is used, when the query actually runs for real the process var indicated is used.

Paul

Avatar

Former Community Member

If I use the "Prameterized Query" then I got the below error:

with no selection of  "Use Parameterized Query" I get no data with the 2nd screen. Note that I am still using LC ES 8.2.1 with SP3. Thanks.NotParaQuery.jpgparaQuery.jpg

Avatar

Former Community Member

I am no SQL expert but shoudln't the last part be "%"?"%".....by having the ? inside of the quotes you are searchng in the DB for a

Commonname that has a ? in it.

Paul

Avatar

Former Community Member

Well, in Oracle DB a single quote should be used instead of double quotes. e.g if I put my name '%HAN DAO%' or 'HAN DAO' then I get some data. If I changed it to double quotes then I would some error like "invalid identifier".

Avatar

Former Community Member

Fine ....but the ? shoudl not be inside the single quotes .....that makes it part of the SQL statement and it will not be interpretted and substituted like it is supposed to be.

Paul

Avatar

Former Community Member

All right, here is how I get it works now by using (commonname like '{$/process_data/@lookupString$}') in the query and set the "*XML Information" like this below. However, I can see there are some records in the xml_result but I do not get the pop up message like "adding ... to the DD list" which cause the DDL does not poopulated. Note that I commented out the line //xfa.data.nodes.remove(oRemoveNode); as you noted in the previous posting as seen on the 2nd screen. Can you please advise. Thanks Paul. Han

FormScreen.JPGXMLInfo.JPG

Avatar

Former Community Member

Paul,

I put some alert msg to debug it and see that it fails/stops at the line " var len = theDataGroup.nodes.length;" with the msg: " theDataGroup is null ".

Thanks,

Han Dao

Avatar

Former Community Member

You are jumping too far ahead .....now that the server side is returning results ....lets make sure that the form is getting those results. Modify the form and hook up the web service call. The result shoudl be put into a field (hidden on the form). Make the field visible so you can visually see that the field is getting populated. Once that is working we can make the next step.

Paul

Avatar

Former Community Member

I actually modified the form with all fields are visible which connect and bind the fields to that service. I do get all the data in the xml_result box but the only thing is the DDL does not populate as it does when I tested your original form that use the LDAP.

Thanks,

Han Dao

Avatar

Former Community Member

We have to walk before we can run ......

It is good that we are getting the web service result into the form. Now there is code behind that field that will load the xml into the data dom and then manipulate it to populate the DDList. The code was written for a particular XML structure ....I doubt that your xml is using the same structure so the code fails. Can you send me a copy of the form and a sample of the xml that is produced? I can then modify the code to take into account your xml strycture and then you should be operational.

You can send the assets to LiveCycle8@gmail.com

Paul

Avatar

Former Community Member

Hi Paul,

I think I figured out the issue that make the DDL is not working right, it's lower-case versus upper-case, I have "people" instead of "People". Now I am dealing with how to get these 3 fields to populate the selection of the DDL. e.g. if I select "Han Dao" from the DDL, it would populate the 3 field with my first name, last name and my email.

Your help would be appreciated.

Thanks,

Han Dao

Avatar

Former Community Member

I sent you an updated sample that uses javascript E4X instead of the data dom....it is much easier using that. Populating the

other fields is easy .....let me know if you need help with that part.

paul

Avatar

Former Community Member

I will post the script that I added to the exit event of the DDlist as I do not have the right to distrubute Han's information without his OK.

See code below:

Paul

//Initialize DDList before starting

DropDownList2.clearItems();

DropDownList2.rawValue

= "";

//Check to see if they entered a search criteria

if

(lookup_string.rawValue == null) {

app.alert('You must enter a search criteria...');

}

else {

//Execute web service

//invokeBtn.execEvent("click")

//Load the returned XML into a E4X javascript variable acall function to clean up the XML

var XMLDoc = new XML(trimXML(xml_result.rawValue));

//Search through xml and grab person nodes

for (i=0;i<XMLDoc.person.length();i++){

//update DDList with common name value

DropDownList2.addItem(XMLDoc.person[i].commonname.toString())

}

}

//Add a No Entry option to the DDList

DropDownList2.addItem("No Entry");

 

/*

* Clean up an XML string so that E4X can handle it.

* We need to: <br/>

* - remove any leading processing instructions<br/>

* - remove any leading whitespace<br/>

* - remove any trailing whitespace<br/>

* @param sXML the xml string to trim

* @return the cleaned up xml string

*/

function

trimXML(sXML)

{

// Remove everything prior to the opening element

sXML

= sXML.replace(/^[\s\S]*?(<[^\?!])/, "$1");

// Remove everything after

return sXML.replace(/(>)[\s]*?$/, "$1");

}