Home » Developer & Programmer » Forms » Save only edited or new records
Save only edited or new records [message #456263] Sun, 16 May 2010 15:24 Go to next message
coolguy01
Messages: 64
Registered: August 2006
Member
Hi,
I have a block based on a table and display a few records on the form after retrieving records from the table behind. Now I should be able to edit a record or add a new record to the existing records on the screen. So when i click the save button I only want the rows which are new or have been edited to go back into the db. This is the piece of code I was using for the save button in the on-button-clicked action.
IF alert_button=alert_button1 THEN
GO_BLOCK('my_block');
IF NOT Form_Success THEN RAISE Form_Trigger_Failure;
END IF;
/* ** Commit if anything is changed */
IF :System.record_Status IN ('CHANGED','NEW') THEN Commit_Form;
END IF;
msg_info('Your changes have been saved.');

END IF;

When I do this all the records on the screen gets inserted into the table instead of only the one's I have edited or newly inserted. I only want to insert rows which are new or edited into the table after I click the save button.
Re: Save only edited or new records [message #456266 is a reply to message #456263] Sun, 16 May 2010 16:17 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
The requirement you describe is defualt forms behaviour - so you've done something to interfere with that.
Why are you writing an code for this at all?
Re: Save only edited or new records [message #456268 is a reply to message #456266] Sun, 16 May 2010 19:07 Go to previous messageGo to next message
coolguy01
Messages: 64
Registered: August 2006
Member
Yes i understand that should be the forms behavior as well but then when i do a form_commit or just commit even the records that were not edited or created newly also get inserted into the db and then i have redundant data in the table.
Re: Save only edited or new records [message #456286 is a reply to message #456268] Mon, 17 May 2010 01:32 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
coolguy01
I have a block based on a table and display a few records on the form after retrieving records from the table behind.

Perhaps the bold part is a culprit. How exactly do you retrieve records? If you did that as usual (i.e. base block on a table, fetch records by executing a query), there wouldn't be any problem.

If you, however, populated a block in a loop, fetching data from a table (in a cursor?) and putting them in a block record by record, then all those records are NEW records although you *think* they are not. Well, they are.

Therefore, commit saves all of them into a table.

If the above is correct, modify behaviour you programmed and use Forms built-in functionalities.
Re: Save only edited or new records [message #456398 is a reply to message #456286] Mon, 17 May 2010 11:12 Go to previous messageGo to next message
coolguy01
Messages: 64
Registered: August 2006
Member
Hi,
Thanx for the explanation. I have based the block of a table in the data source but then I have procedure which contains a loop that populates the table. I think this cursor loop might be the culprit. But my problem is I don't have to query and populate everything in the table to the block. I have a few search criteria based on which I have to retrieve only a few records and populate only those on the screen. Hence the procedure. So if i need to use commit_form and let form form handle the commit itself how do i handle display only selected records while retrieving from the base table.
Re: Save only edited or new records [message #456401 is a reply to message #456398] Mon, 17 May 2010 11:40 Go to previous message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
As suggested in some of your other threads:
Set the blocks where clause using either default_where or onetime_where.
Or for simple search criteria just use enter-query mode.
Then use execute_query.

You should never populate a block with a cursor like that if you want to modify the data. In fact you should just never do it.

I suspect this is also why you are having problems with delete_record.
Previous Topic: problem using java bean with baseHTMLjinitiator=basejpi.htm ?
Next Topic: Insert and Update directly into table from pre update trigger of block based on same table
Goto Forum:
  


Current Time: Fri Sep 20 05:55:18 CDT 2024