Expand my Community achievements bar.

Providing interactive database lookup from forms

Avatar

Former Community Member
I am currently learning how to use Adobe LiveCycle Designer 7.0. My employer gave me the file to install a trial version along with pdf files with tutorials explaining how to use it. I am having trouble with the tutorials that involving scripting. Though I copy the script code directly from the pdf and follow the instructions. I have a hard time getting it to work correctly.



The one that I have had the most problem with is the tutorial entitled "Providing Interactive database lookup from forms. I followed the instructions to create a new data connection from the mdb file provided. There was a script to populate a drop down box that I was able to get to work after changing the syntax a bit. However the script that is on the button to execute the query I couldn't ever get to work.



Here are the instructions copied directly from the pdf.



13. Select the Refresh object. In the Script Editor, choose the following:

Show: click

Language: FormCalc

Run At: Client



14. In the Script editing area, type the following code:



if (Len(Ltrim(Rtrim(SelectField.rawValue))) > 0) then

$sourceSet.DataConnection.#command.query.commandType = text

$sourceSet.DataConnection.#command.query.select.nodes.item(0).value = Concat(Select * from OfficeSupplies Where ID = , Ltrim(Rtrim(SelectField.rawValue)) ,)



//Reopen the Dataconnection

$sourceSet.DataConnection.open()



endif



Whenever I click the button I received the following error:








Any suggestions on what I might be doing wrong?
5 Replies

Avatar

Level 1
Hi Jason ,



I have the problem .

I am looking for the answer.



Jean-Yves

Avatar

Former Community Member
Are you using Reader or Acrobat? That's typically an error message when you try to do that in Reader. You cannot do DB access in Reader, unless the PDF has had extra usage rights given to it using Reader Extensions.



Chris

Adobe Enterprise Developer Support

Avatar

Level 1
Hi Chris,



I am using Reader .

But you said we cannot do DB access in Reader but why does the ComboBox (Select ID) in your example purchase.pdf work ?



Regards,



Jean-Yves RANCUREL

Avatar

Former Community Member
I'm not sure, I don't really remember what I did in that sample, do you have a link to where I posted it? I know there was a bug in Reader where the first record from the record set would appear, but the DB data connection would be unusable from there, so maybe that's why it looks like it works in Reader. But unless a PDF is reader extended it is not supposed to be able to access a DB from Reader.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Chris,



Is there a way that I can get a trial version of Reader Extensions? I can't seem to find one anywhere online. All I have been able to find is a zip file with a tutorial inside that tells how to add extensions to a pdf file. I has the code below but no explanation of where to add this code within the pdf. I am assuming I need some sort of software to do this. Can you please elaborate?



Object o;

ConnectionFactory connectionFactory;

InitialContext namingContext = new InitialContext();



//

// Start a transaction so the server will know when it can clean

// up after itself.

//



UserTransaction transaction = (UserTransaction) namingContext.lookup

("java:comp/UserTransaction");

transaction.begin();

try

{



//

// Create PDF manipulation object. We will use this object

// to enable usage rights for the PDF document.

//



o = namingContext.lookup("PDFManipulation");

connectionFactory = (ConnectionFactory) PortableRemoteObject.narrow

(o,ConnectionFactory.class);

PDFFactory pdfFactory = PDFFactoryHelper.narrow

((org.omg.CORBA.Object)connectionFactory.getConnection());



//

// Create a data manager object. The data manager creates the

// objects that we need to pass to the PDF manipulation object.

//



o = namingContext.lookup("DataManagerService");

connectionFactory = (ConnectionFactory) PortableRemoteObject.narrow

(o,ConnectionFactory.class);

DataManager dataManager = DataManagerHelper.narrow

((org.omg.CORBA.Object)connectionFactory.getConnection());



//

// Read the PDF document into the DataBuffer that we need for

// the PDF manipulation object to work with.

//



String contentUrl =

request.getScheme() + "://" +

request.getServerName() + ":" +

request.getServerPort() +

request.getContextPath() +

samplePath;

DataBuffer pdfFile = dataManager.createFileDataBufferFromUrl

(contentUrl + "/sample.pdf");

PDFDocument pdfDoc = pdfFactory.openPDF(pdfFile);



//

// With a usage rights credential, enable specific rights.

//



Credential credential =

new Credential("myusagerights", "password".getBytes());

String[] rights = new String[2];

rights[0] = FORM_FILL_IN.value;

rights[1] = SIGNING_MODIFY.value;

String message = "You may fill in forms or sign the document.";

pdfDoc.setUsageRights(credential, rights, message, true);



//

// Get the modified PDF document.

//



DataBuffer result = pdfDoc.save();



//

// Here we create a temporary file in the form of a SessionTempFile.

// The SessionTempFile object creates a temporary file and

// implements a session listener to erase the file when the

// session terminates. The temporary file will hold the extracted

// certificate so we can refer to it from the next page.

//



HttpSession session = request.getSession();

SessionTempFile stf = new SessionTempFile("step1", ".pdf");

session.setAttribute(samplePath + "/step1.pdf", stf);

OutputStream os = new FileOutputStream(stf.getFile());

os.write(result.getBytes(0L, result.getBufLength()));

os.close();

}

catch (Exception error)

{

//

// terminate the transaction when there is an exception

//

transaction.rollback();

throw error;

}



//

// Let the server clean up its temporary storage.

//



transaction.commit();



//

// Redirect the browser to the next page.

//



response.sendRedirect("finished.jsp");

return;



Thanks for your help.