Expand my Community achievements bar.

Select Record from List - Error Violates Permission Settings

Avatar

Level 3

Greetings:

I am trying to select a record(s) from a data list box and I am getting an error message:  "Property: 'commandType' cannot be set because doing so would violate the permission settings."

I am using Designer ES2 9.0 and xfa 2.5.

I have successfully connected to the database and my list box is populated with the names from my table (newcal1).  The error message flashes when I hit the button to select a particular record.

I have read everything I can get my hands on, and spent all day yesterday trying to solve this problem.  Here is the code on the "click" event for the button in formcalc:

var

sCategoryId = xfa.event.newText

var

oDC = Ref($sourceSet.DataConnection.clone(1))

//Change the commandType from TABLE to TEXT. TEXT

//is the equivalent of SQL Property

$sourceSet.DataConnection.#command.query.commandType

= "text"

//Set the Select Node. Select in this case will be

//whatever SQL Property you want

$sourceSet.oDC.#command.query.select.nodes.item(0).value

= Concat("Select*from newcal1 Where DefName = '", DataListBox.rawValue,"'")

//Reopen the Data connection

$sourceSet.oDC.open()

Can you help?

7 Replies

Avatar

Former Community Member

Staring in version 8 the sourceSet dom was locked down for security reasons so when you try and change the command type to query that is where the security error is coming from. You can get around this by cloning the sourceSet dom and using the cloned dom instead....I use Javascript in my scripts and here is what I do :

var

inName = xfa.event.newText;

if

(inName == ""){

app.alert("You must enter a valid name - try again!")

}

var

nIndex = 0;

while

(xfa.sourceSet.nodes.item(nIndex).name != "DataConnection2")

{

nIndex

++;

}

var

oDB = xfa.sourceSet.nodes.item(nIndex).clone(1); // the node pertaining to the data connection specified

//app.alert(oDB.saveXML("pretty"));

//set up sql call to DB to get specifics about employee

oDB.nodes.item(1).query.setAttribute("text"

, "commandType");

oDB.nodes.item(1).query.select.nodes.item(0).value

= "Select * from table1 where AcctNumber = '" + inName + "'";

//app.alert(oDB.nodes.item(1).saveXML("pretty"));

//now connect to DB and get a record

oDB.open()

oDB.close();

Note the line in red and underlined. This is where I clone the sourceset and from there on I use the cloned dom. If you want a more detailed explanation Stefan Cameron discusses this in his blog.

http://blogs.adobe.com/formbuilder/2006/12/better_form_design_with_xfa25.html

Paul

Avatar

Level 3

Thank you Paul.

Where do you put this code?  I was using a list box and a button to select the record and had my code on the "click" event of the button.

Avatar

Former Community Member

When  I am developing I use a button click event, once it is working I move it to the exit event of the DDList.

Paul

Avatar

Level 3

I have tried this code on both the click event of a button and the exit event of a list box (I am not using a DDList).  In both instances, I get an error message: "You must enter a valid name - try again." 

Any suggestions?

Avatar

Former Community Member

The xfa.event.newText is only useful when you use the Change event. After that it is empty so your check for a null is working. Change it to this.rawValue and that will return the value that was chosen. It makes no diff if it is a DDList or a ListBox, they work the same.

Paul

Avatar

Level 3

Paul, you are a genius.  Thank you so much. 

Now, my next question:  My list box includes all the names in a table.  In some instances, a name is listed twice because there are two records associated with the name.  Is it possible to select both records for one form?  I am able to select one record, but not both records. 

Avatar

Former Community Member

If you return more than 1 record how are you going to display multiple values in individual fields?

Paul