Records getting deletd if not selected [message #627713] |
Fri, 14 November 2014 23:24 |
|
tara_260985
Messages: 46 Registered: November 2014
|
Member |
|
|
Hi all,
I have certain records in a table format in a block and have a delete button associated with it.
If i dont select any record and simply press the delete push button ,it deletd the 1st record from the screen, also if I place my cursor out of the block anywhere in the form and press the delete button it deletes the first record automatically.
Please help
|
|
|
|
|
|
|
Re: Records getting deletd if not selected [message #627787 is a reply to message #627762] |
Sun, 16 November 2014 22:23 |
|
tara_260985
Messages: 46 Registered: November 2014
|
Member |
|
|
This is my code which gets fired on Delete push Button-when button pressed.
PROCEDURE P_DELETE IS
L_error_message RTK_ERRORS.RTK_TEXT%TYPE;
L_cursor_item VARCHAR2(100) := :system.cursor_item;
L_current_record NUMBER(4) := Get_Block_Property('B_AAP_ITEM_XREF', CURRENT_RECORD);
L_reset_validation BOOLEAN := FALSE;
BEGIN
Issue_Savepoint('DELETE');
---
--- Make sure that validation does not fire for the current item.
if Get_Item_Property(L_cursor_item, ITEM_TYPE) = 'TEXT ITEM' then
Set_Item_Property(L_cursor_item, ITEM_IS_VALID, PROPERTY_TRUE);
L_reset_validation := TRUE;
end if;
if Get_Record_Property(Get_Block_Property('B_AAP_ITEM_XREF', CURRENT_RECORD),
'B_AAP_ITEM_XREF',
STATUS) in ('NEW', 'INSERT') then
Go_Block('B_AAP_ITEM_XREF');
Delete_Record;
else
Go_Block('B_AAP_ITEM_XREF');
Delete_Record;
Post;
Window_Handler.Set_Form_Changed;
Set_Application_Property(CURSOR_STYLE, 'DEFAULT');
end if;
--- Make sure that any applicable validation will execute for the current item.
if L_reset_validation = TRUE then
Set_Item_Property(L_cursor_item, ITEM_IS_VALID, PROPERTY_FALSE);
end if;
---
EXCEPTION
when FORM_TRIGGER_FAILURE then
Issue_Rollback('DELETE');
--- Reset the multi-record block.
Go_Block('B_AAP_ITEM_XREF');
Clear_Block(No_Validate);
Execute_Query;
--- Navigate to the record selected before this program unit executed.
Go_Record(L_current_record);
Go_Item(L_cursor_item);
--- Make sure that any applicable validation will execute for the current item.
if L_reset_validation = TRUE then
Set_Item_Property(L_cursor_item, ITEM_IS_VALID, PROPERTY_FALSE);
end if;
Set_Application_Property(CURSOR_STYLE, 'DEFAULT');
raise;
when OTHERS then
emessage (SQLERRM);
raise FORM_TRIGGER_FAILURE;
END;
[EDITED by LF: applied [code] tags]
[Updated on: Mon, 17 November 2014 00:08] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: Records getting deletd if not selected [message #627796 is a reply to message #627792] |
Mon, 17 November 2014 03:13 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
I thought (and this is distant memory here since I'm not in a position to test) that go_block want to the last selected record in the block.
In which case some other code is causing it to navigate to the first record.
I'm not sure why any of this code has been written mind you - what's wrong with just using the delete button on the tool bar?
But if you really want a separate button, putting it in the B_AAP_ITEM_XREF datablock while probably simplify your navigation issues.
|
|
|
|
|
Re: Records getting deletd if not selected [message #627859 is a reply to message #627810] |
Mon, 17 November 2014 09:22 |
|
CraigB
Messages: 386 Registered: August 2014 Location: Utah, USA
|
Senior Member |
|
|
The Forms Help System doesn't clearly state where the navigation cursor will go when the GO_BLOCK built-in is executed. However, as Littlefoot explained, the GO_BLOCK will send the navigation cursor to the first navigable record; this can be discovered through basic trial and error testing.
Looking at your code, I think you have over complicated things. Your code suggests that your button is in your Data Block therefore, there is no need to call the GO_BLOCK() built-in because you are already in the right block. If you're going to use the GO_BLOCK() then you also need to call the GO_RECORD() and tell it to go to the L_CURRENT_RECORD that you set in the declaration.
Your code is very confusing...
if Get_Item_Property(L_cursor_item, ITEM_TYPE) = 'TEXT ITEM' then
Set_Item_Property(L_cursor_item, ITEM_IS_VALID, PROPERTY_TRUE);
L_reset_validation := TRUE;
end if;
...
...
--- Make sure that any applicable validation will execute for the current item.
if L_reset_validation = TRUE then
Set_Item_Property(L_cursor_item, ITEM_IS_VALID, PROPERTY_FALSE);
end if;
What is the purpose of this? This makes me think you are trying to validate the record you just deleted. What does this accomplish?
if Get_Record_Property(Get_Block_Property('B_AAP_ITEM_XREF', CURRENT_RECORD),
'B_AAP_ITEM_XREF',
STATUS) in ('NEW', 'INSERT') then
Go_Block('B_AAP_ITEM_XREF');
Delete_Record;
else
Go_Block('B_AAP_ITEM_XREF');
Delete_Record;
Post;
Window_Handler.Set_Form_Changed;
Set_Application_Property(CURSOR_STYLE, 'DEFAULT');
end if;
Why are you trying to delete a record from the database that hasn't been committed to the database yet? If the record status is NEW or INSERT it means the record doesn't exist in the base table and Forms will perform an INSERT DML action during Commit processing. If the Record Status is CHANGED, then Forms will perform an UPDATE DML action during Commit processing. Therefore, the DELETE_RECORD() will fail if the first condition is true. You should call the CLEAR_RECORD instead. In both cases, after you call GO_BLOCK, you need to call GO_RECORD(L_current_record) so you are on the correct record before you call CLEAR_RECORD or DELETE_RECORD. For example:
if Get_Record_Property(Get_Block_Property('B_AAP_ITEM_XREF', CURRENT_RECORD),
'B_AAP_ITEM_XREF',
STATUS) in ('NEW', 'INSERT') then
Go_Block('B_AAP_ITEM_XREF');
GO_RECORD(L_current_record);
Clear_Record;
else
Go_Block('B_AAP_ITEM_XREF');
GO_RECORD(L_current_record);
Delete_Record;
Post;
Window_Handler.Set_Form_Changed;
Set_Application_Property(CURSOR_STYLE, 'DEFAULT');
end if;
Craig...
|
|
|
Re: Records getting deletd if not selected [message #627860 is a reply to message #627859] |
Mon, 17 November 2014 09:33 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
CraigB wrote on Mon, 17 November 2014 15:22
Why are you trying to delete a record from the database that hasn't been committed to the database yet? If the record status is NEW or INSERT it means the record doesn't exist in the base table and Forms will perform an INSERT DML action during Commit processing. If the Record Status is CHANGED, then Forms will perform an UPDATE DML action during Commit processing. Therefore, the DELETE_RECORD() will fail if the first condition is true.
Are you aure about that? Again I may be misremembering but I believe that delete_record will work the same as clear_record if the record in question doesn't exist in the DB.
|
|
|
|
|
Re: Records getting deletd if not selected [message #628038 is a reply to message #628037] |
Wed, 19 November 2014 07:51 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
The fundamental problem here is that the cursor is in the wrong record when you call delete_record, calling clear_record will not change that fact. As Craig already said, you need to use go_record to go to the correct record first, or avoid leaving the B_AAP_ITEM_XREF block in the first place so go_block isn't needed either.
Using the standard delete button on the toolbar will avoid these issues - so I've got to ask again, why aren't you using it?
|
|
|
|
|
|
|
|
|
|
|
|
|