Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Accessing XML Data from JavaScript

Avatar

Level 2
How would I go about accessing the current XML data within a javascript initialize function?



If i have an xml file:

<fields>

<AcctNm>Testing</AcctNm>

<AcctNm>Testing2</AcctNm>

<AcctNm>Testing3</AcctNm>

</fields>



How would i get to the array containing these values while a javascript initialization function is executing?

I've tried

app.alert($record.AcctNm[1]);

but its coming back as undefined?



app.alert($record.AcctNm);

is of type [object xfaObject], but how do I access individual elements and what method gets at the text within the xml file?



Thanks
7 Replies

Avatar

Level 5
$record.fields.AcctNm[1].value should give you the value you are looking for. With out having ".value" at the end it will consider it as just an object.

Avatar

Level 2
Thanks for the response, that got me closer..



Unfortunately the index seems to be giving me problems.

Javascript debugger reported:

TypeError: $record.fields.AcctNm[1] has no properties

5:XFA:fields[0]:ready



When i remove the index so it looks like

$record.fields.AcctNm.value



I get the first value, 'Testing'. I'm confused as to why the indexing causes an error.... Any ideas??



Thanks again.

Avatar

Level 5
try the following...check if that makes an difference.

var AcctNms = $record.fields.AcctNm[*]

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

AcctNm = AcctNms.item(i).value;

}



or you may simply try

$record.fields.AcctNm.item(1).value;



let us know the results.

Avatar

Level 2
Hmm somethings not jiving here...



The loop actually crashes livecycle designer...



The single line statment gets the following error:

TypeError: $record.fields.AcctNm.item is not a function

1:XFA:fields[0]:ready



I'm using livecycle 8.0, does that make a difference?



I'm stumped..



Thx

Avatar

Level 5
Did you declare AcctNm? it works both in LC 7.1 and 8.

I have similar scenario in one of my forms and the Loop works for me. I guess you have to tweak the following to suite your requirement and context.



AcctNm = AcctNms.item(i).value;



try changing some thing one or two times if you did not get pass the issue I can help you at "meetsekharv AT yahoo.com" if you can email me your form and XML.

Avatar

Level 2
I figured out how to access it in a different manner,



$record.fields.nodes.item(i).value



is giving me the ith zero-based value.

I should be able to ensure I'm getting AcctNm fields by checking

the name property before using the value.



I'm not sure why the other methods don't work....

Avatar

Former Community Member
I have a vital form that clients fill out, which is passed to many people in the company along the workflow. The form is a Planner and we have in the following PDF, Word Doc..



Well before, the Planner.pdf was originally created in Word, since most people have access to Word.. but evolved to a PDF form created from the Word Doc via Adobe LiveCycle Designer 8.0 w/ User Rights enabled so that the form could be filled out and saved using Adobe Reader.. which was a step better than Word.. being that it is free. But this needed to be easier and more to the point b/c some clients don't particularly like installing the latest version of Reader, even if you provide them the link. Nor do they like saving the form, filling the form, and attaching the form to send back.



My goal is to have the client fill an HTML version of the form, submit and be done with it, but everyone in the workflow be able to easily receive the filled Planner as a PDF form.



So some months ago I ran into this post Chris Trip, "Populate Livecycle PDF from mySQL database using PHP" #8, 22 Sep 2007 4:37 pm



which uses the command line Win32 pdftk.exe to merge an FDF file into an existing PDF on the remote server, and serve this to whoever.



My problem was with shared hosting and having the ability to use the Win32 pdftk.exe along with PHP which is predominantly used on Linux boxes. And we used a Linux box.



so i created the following unorthodox method, which a client fills the HTML version of the Planner, all field values are INSERTED into a table in MySQL DB, I and all filled planners that have been filled by clients to date can be viewed from a repository page where an XML file is served up of the corresponding client, but someone would have to have Acrobat Professional, to import the form data from the XML file into a blank form.. altoughh this is simple for me.. I have the PHP file already created so that when a Planner is filled and client submits. >> the an email is sent to me with a table row from the repository of the client name, #, email, and a link to d-load the XML file,



But I also have the PHP files created so that the Planner can be sent to by email to various people in the workflow with certain fileds ommitted they they do not need to see, but instead of the XML file beiong served up i need the filled PDF Planner to be served.



I can do this locally with ease on a testing server, but I am currently trying to use another host that uses cross-platform compatibility so i can use PHP and the pdftk.exe to achieve this, as that is why I am having to serve up an XML file b/c we use a Linux server for our website, and cant execute the exe.



Now that I am testing the other server (cross-platform host), just to use them to do the PDF handling (and it's only $5 per month) I am having problems with getting READ, WRITE, EXECUTE permissions..



Si guess a good question to ask is can PHP do the same procedure as the pdftk.exe, and i can eleminate it.



or how in the heck can i get this data from the DB into a blank PDF form, like i have described??



here are some link to reference



Populating a LiveCycle PDF with PHP and MySQL

http://www.andrewheiss.com/Tutorials?page=LiveCycle_PDFs_and_MySQL



HTML form that passed data into a PDF

http://www.mactech.com/articles/mactech/Vol.20/20.11/FillOnlinePDFFormsUsingHTML/index.html

and an example

http://accesspdf.com/html_pdf_form/