Home » Developer & Programmer » Forms » Records getting deletd if not selected
Records getting deletd if not selected [message #627713] Fri, 14 November 2014 23:24 Go to next message
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 #627732 is a reply to message #627713] Sat, 15 November 2014 08:27 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
That's most probably because you wrote it that way. What's in the WHEN-BUTTON-PRESSED trigger associated with the DELETE button?
Re: Records getting deletd if not selected [message #627755 is a reply to message #627732] Sat, 15 November 2014 12:14 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
I have given delete_record inbuilt function and current_record
what needs to be done,I have also used system.cursor_line ..but still its not helping..
Re: Records getting deletd if not selected [message #627760 is a reply to message #627755] Sat, 15 November 2014 15:15 Go to previous messageGo to next message
mughals_king
Messages: 391
Registered: January 2012
Location: pakistan
Senior Member
Sir @Littlefoot is right take screen shot and upload let us know what you are willing to do and how.

Regards
Mughal

[Updated on: Sat, 15 November 2014 15:15]

Report message to a moderator

Re: Records getting deletd if not selected [message #627762 is a reply to message #627755] Sat, 15 November 2014 15:56 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
tara_260985 wrote on Sat, 15 November 2014 19:14
I have given delete_record inbuilt function and current_record
what needs to be done,I have also used system.cursor_line ..but still its not helping..

Instead of (unsuccessfully) describing what you did, why don't you copy/paste the whole trigger? Because, you are talking nonsense. What is "system.cursor_line"?

Anyway: it seems that the trigger does what you wanted it to: it deletes the first record in the block (at least, that's what DELETE_RECORD does).
Re: Records getting deletd if not selected [message #627787 is a reply to message #627762] Sun, 16 November 2014 22:23 Go to previous messageGo to next message
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 #627788 is a reply to message #627787] Mon, 17 November 2014 00:13 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
"if Get_Record_Property" says that whenever you push a button, the first record in the B_AAP_ITEM_XREF block is deleted as both IF and ELSE contain GO_BLOCK (which navigates to the first record in the block) and then DELETE_RECORD (which deletes the first record in the block).
Re: Records getting deletd if not selected [message #627789 is a reply to message #627788] Mon, 17 November 2014 00:30 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
in that case what needs to be done,kindly assist.
Re: Records getting deletd if not selected [message #627792 is a reply to message #627789] Mon, 17 November 2014 00:59 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Plug in your brain. Think! It is your form, your button, you decide what you want to do when it is pressed.
Re: Records getting deletd if not selected [message #627796 is a reply to message #627792] Mon, 17 November 2014 03:13 Go to previous messageGo to next message
cookiemonster
Messages: 12957
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 #627807 is a reply to message #627796] Mon, 17 November 2014 04:22 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Nope, GO_BLOCK goes to the first record in the block. At least, that's what happened when I just tried it (Forms 10g) which just confirms what I thought & wrote.
Re: Records getting deletd if not selected [message #627810 is a reply to message #627807] Mon, 17 November 2014 04:31 Go to previous messageGo to next message
cookiemonster
Messages: 12957
Registered: September 2008
Location: Rainy Manchester
Senior Member
Fair enough, it's been a long time since I did any forms coding of my own I misremembered.
Re: Records getting deletd if not selected [message #627859 is a reply to message #627810] Mon, 17 November 2014 09:22 Go to previous messageGo to next message
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 Go to previous messageGo to next message
cookiemonster
Messages: 12957
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 #627885 is a reply to message #627860] Mon, 17 November 2014 16:19 Go to previous messageGo to next message
CraigB
Messages: 386
Registered: August 2014
Location: Utah, USA
Senior Member
Quote:
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.

Cookiemonster, you are most likely right. The DELETE_RECORD will likely work the same as a CLEAR_RECORD since Forms will flag the record for delete in the same way it will flag the record for INSERT or UPDATE and then apply the changes during commit processing. Essentially, the DELETE_RECORD will cancel out the INSERT_RECORD or UPDATE_RECORD.

Craig...
Re: Records getting deletd if not selected [message #628037 is a reply to message #627713] Wed, 19 November 2014 07:08 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
@ Craig,I tried clear_record but its functioning the same as delete_record.
Re: Records getting deletd if not selected [message #628038 is a reply to message #628037] Wed, 19 November 2014 07:51 Go to previous messageGo to next message
cookiemonster
Messages: 12957
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?
Re: Records getting deletd if not selected [message #628081 is a reply to message #628038] Thu, 20 November 2014 01:22 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
I have attached the image of the form, now in this I want to delete the selected record.
Can u guide me where can I get delete button on the standard toolbar?
I have modified my query to -

PROCEDURE P_Delete IS
L_current_record NUMBER(4):= Get_Block_Property('B_AAP_ITEM_XREF', CURRENT_RECORD);
BEGIN
if show_alert('ALT_DELETE_WARNING')=alert_button1
then
go_record(L_current_record);
delete_record;
END IF;
END;

still not happening Sad
  • Attachment: form.png
    (Size: 60.74KB, Downloaded 70 times)
Re: Records getting deletd if not selected [message #628082 is a reply to message #628081] Thu, 20 November 2014 01:28 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You don't have the standard toolbar.

I guess that one DELETE button - the one you have it in the "Item XREF Number" block - would be OK. Just put it into the same block - you'll most probably see 4 of them. Then open button's Property Palette and set "Number of items displayed" to 1. Once you do that, you don't need any navigation any more - simply raise the ALT_DELETE_WARNING alert and DELETE_RECORD.
Re: Records getting deletd if not selected [message #628092 is a reply to message #628082] Thu, 20 November 2014 03:01 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
@Littlefoot
Just put it into the same block - you'll most probably see 4 of them.?????


means???
Re: Records getting deletd if not selected [message #628099 is a reply to message #628092] Thu, 20 November 2014 03:16 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
@ Littlefoot: I tried your solution,but its not working,also when I press delete button without selecting any record,the first record is getting deleted automatically.
also I want to create a alert,if user press the delete button without selecting any record,it should given a alert to a user to select a record from that block.
Re: Records getting deletd if not selected [message #628108 is a reply to message #628099] Thu, 20 November 2014 03:51 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
guys I am able to delete the selected record now Smile
Thanks a lot
Re: Records getting deletd if not selected [message #628110 is a reply to message #628108] Thu, 20 November 2014 03:55 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
But now my problem is...if I press my delete button without selecting any record, the first record is getting deleted automatically.

My requirement is : when user press the delete button without selecting any record, the first record is should not get deleted automatically
Re: Records getting deletd if not selected [message #628114 is a reply to message #628110] Thu, 20 November 2014 04:20 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Didn't I see you raising an alert? It should say "Do you really want to delete that record?" which would prevent you to accidentally & automatically delete ANY record.
Re: Records getting deletd if not selected [message #628117 is a reply to message #628114] Thu, 20 November 2014 04:39 Go to previous messageGo to next message
tara_260985
Messages: 46
Registered: November 2014
Member
the alert which I raised ,if user presses Yes on that alert,it shouldnt delete the first record from the block automatically,infact it should tell the user"select a record to delete"
Re: Records getting deletd if not selected [message #628145 is a reply to message #628117] Thu, 20 November 2014 06:24 Go to previous messageGo to next message
Littlefoot
Messages: 21266
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Phew, I don't know why I'm participating the most complex way of a simple action like deleting a record ...

So create another checkbox item in that block and make deleting even more complex: force users to explicitly check records they want to delete. Then let them push the button. Ask them whether they really want to delete marked records. Even better, ask them twice ("are you really really sure?"). Once they are sure, perform delete operation (but this time you'll have to loop through the block).

So, how about leaving your phone number on that form, saying "In case of deleting a record, call my hot line on 555-1234 and I'll do it for you"?
Re: Records getting deletd if not selected [message #628201 is a reply to message #628145] Fri, 21 November 2014 02:44 Go to previous message
tara_260985
Messages: 46
Registered: November 2014
Member
hehehe:-) I was thinking the same..its basically client requirement.
Previous Topic: Check if details exist before saving master record..
Next Topic: Oracle 11gR2 forms and Report Installation - Error in Installation Progress
Goto Forum:
  


Current Time: Thu Dec 14 17:11:40 CST 2017

Total time taken to generate the page: 0.02077 seconds