Home » Developer & Programmer » Forms » autogenerate
icon14.gif  autogenerate [message #168770] Sat, 22 April 2006 08:18 Go to next message
andirajkumar
Messages: 9
Registered: April 2006
Location: india
Junior Member

for my project invoice nos should be autogenerated. when the user presses a button new the invoice nos should be generated. what trigger i should use at what level and code for the trigger. kindly guide me. bye
Re: autogenerate [message #168823 is a reply to message #168770] Sun, 23 April 2006 08:32 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
One way would be to use a sequence in the WHEN-NEW-RECORD-INSTANCE trigger.
Re: autogenerate [message #168858 is a reply to message #168823] Sun, 23 April 2006 19:58 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Sorry, wrong answer, use the When-Create-Record trigger. The When-New-Record-Instance fires EVERYTIME you move to another record. WCR fires only when you go to a record that has just been created (that is, 'new'). Yea, I know that the WNRI SOUNDS like the right trigger but have a look at the documentation and you will see the differences.

David
Re: autogenerate [message #168881 is a reply to message #168858] Mon, 24 April 2006 00:18 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I see (and apologize to Andirajkumar if my wrong answer caused any problems) ... as I don't have Forms here to try it myself, does it mean that use of the When-new-record-instance trigger makes a good chance to end up with "Do you want to save changes" question?
Re: autogenerate [message #168883 is a reply to message #168881] Mon, 24 April 2006 00:39 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Littlefoot,

Thank you for the many great suggestions that you have given to the various newbees that post in this forum and I am always grateful to you for answering questions that I am sick of answering, between us and MHE we get to handle most of these people.

Yes, I also was inclined to put code into the WNRI trigger when I should really only put it into the WCR trigger. Its the word 'NEW' that throws you off balance. 'New' here does not mean 'first time' but 'I am dealing with a record different to the last record'. It is the 'create' trigger that should be used to populate items. You could use the WNRI trigger and test to see if the item is already populated before putting a value into it but have a read of the reference manual and for WCR it says
Description

Fires when Form Builder creates a new record. For example, when the operator presses the [Insert] key,
or navigates to the last record in a set while scrolling down, Form Builder fires this trigger.
I would also like to reiterate that we should use the Post-Query trigger, and not the WNRI trigger, to do code and other look-ups.

David
Re: autogenerate [message #168885 is a reply to message #168883] Mon, 24 April 2006 01:11 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Thank you for the explanation, David! There's still so much to learn for me, I'm afraid Smile
Re: autogenerate [message #169530 is a reply to message #168883] Thu, 27 April 2006 08:18 Go to previous messageGo to next message
andirajkumar
Messages: 9
Registered: April 2006
Location: india
Junior Member

friends am happy thatt u have responded. i am starting to understand. what i need is the code for the trigger in detail and also at what level the trigger should be? item level?
thanks a lot.
Re: autogenerate [message #169591 is a reply to message #169530] Thu, 27 April 2006 12:19 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It seems that we are a happy little family here, on this topic; 2/3rds of us are learning some facts from the rest 1/3rd. But, don't you think that you got enough information to start researching by yourself? Register and read how to manage sequences; return with the code you wrote (yes, I agree, it would really be nice to get it with no effort at all) and ask for help when needed.
Re: autogenerate [message #169853 is a reply to message #169591] Sat, 29 April 2006 08:22 Go to previous messageGo to next message
andirajkumar
Messages: 9
Registered: April 2006
Location: india
Junior Member

i created a button new for creating a new record. i used the when create record trigger for this button and wrote the following code,
insert into sales_order_mas(invoice_no)
values(serialnos.seq.nextval);
but nothing happened. i think u can understand my problem
when the user presses new to create a new record invoicenos should be generated starting with 1. i have already created a sequence.kindly guide me with code and trigger.
Re: autogenerate [message #169942 is a reply to message #169853] Sun, 30 April 2006 22:40 Go to previous message
samit_gandhi
Messages: 226
Registered: July 2005
Location: Hong Kong
Senior Member

if u have already generated the sequence in the database than why u r using insert into statment in ur code. use assignment operator for the value of the form like :

:<block_name>.<field_name>=:<sequence_name>.next_val

it will automatically take the next value from the sequece and store it in the field of that block

samit
Previous Topic: master-detail relationship
Next Topic: when i press the save button in a master detail form
Goto Forum:
  


Current Time: Fri Sep 20 07:49:15 CDT 2024