Expand my Community achievements bar.

problems with addNew... it doesnt work

Avatar

Former Community Member
Its is my problem.

I have created a data connection and its works. I know this because I can delete records from record set or i can move to the previous record in the record set.

But if i use addnew nothing happens. I try a lot and i dont have reponse



xfa.sourceSet.prueba1.addNew();



Only th fileds change to delete entry but nothing change in the record set

Thans in advance and sorry about my english
11 Replies

Avatar

Former Community Member
Addnew() method only adds a new record. You will need to use update() method in conjunction with Addnew() method to sucessfully insert data into the new record.



For example: assume your table has 2 columns named "firstname" and "lastname". Here is what you need to put on the click event of the button. "DataConnection" is the name of your data connection.



temp1.rawValue = firstname.rawValue;

temp2.rawValue = lastname.rawValue;

xfa.sourceSet.DataConnection.addNew();



firstname.rawValue = temp1.rawValue;

lastname.rawValue = temp2.rawValue;

xfa.sourceSet.DataConnection.update();

Avatar

Former Community Member
ty very much. I did it, but my next question is. which is the diference between use addnew and update and only update because before you respose i used only update and I got the prospective result.

Avatar

Former Community Member
When you call the update() method, it only updates the current record with your new data.

Avatar

Former Community Member
ty very much i appreciate your help. If i have more questions i will post it.

Avatar

Former Community Member
one more question. When i open my form with acrobat, th form get the first record from my database. Can i avoid this?

Avatar

Former Community Member
When you setup your Data connection, on the last screen (ADO properties), there is an option called "Delayed Open". If you check this box, I believe you will avoid the first record to be shown.

Avatar

Former Community Member
I did "Delayed Open". Then, if i want to update recod i need to open first the connection. I use sourceset.dataconection.open()

but

then i can not record my data with update

and

if i use

temp1.rawValue=prueba1.rawValue;

temp2.rawValue=prueba2.rawValue;

temp3.rawValue=p3.rawValue;

etc (you told me in your firts reponse)

th java console respond:

ReferenceError: temp1 is not defined

1:XFA:form1[0].#subform[0].Button2[0]:click

which is my mistake?

Avatar

Former Community Member
You can take a look at this post. I have an example of how to look up a record based on one given field of that record.




jimmypham, "Data Connection - Search for record" #1, 29 Aug 2005 1:47 pm

Avatar

Former Community Member
I an trying to add a new record to the database via. I have created two form buttons, and label

them Add New Record and Save. Select the Add New Record form button, and in the Script Editor under

the Click event for this button enter sourceSet.DataConnection.addNe

When this button is clicked, it suposes it will create a new record to the recordset.

Then fill in the form fields with the new data, and then click the second button, with the script sourceSet.DataConnection.Update();

but.. i have the next message:



XFAObject.update:1:click undefined:Exec

Operación fallida de updateRecord. Multiple-step operation generated errors. Check each status value.[Id:11]



can you help me? it suposes This error means that one or more fields you are inserting/updating contain an invalid value, but it is no case

Avatar

Former Community Member
When I tried using the code mentioned above, I got an error:



Error:updateRecord operation failed. Non-nullable column cannot be updated to Null.[Level:10]



What gives?

Avatar

Former Community Member
Just to clarify, I received the error mentioned in message #9 when I use the code mentioned in message #1 of this thread.