Code to get next sequence #

I want to be able to automatically populate my ID field with the next sequence # when I click the "add row" button from the NavBar. What code would I use and where would I put it to populate the textfield control which is bound to the ID column.
thanks

The code is very simple:
public void create(AttributeList attributeList)
super.create( attributeList );
SequenceImpl s =
new SequenceImpl("SEQ_NAME", getDBTransaction());
Integer next = (Integer) s.getData();
setId(new Number(next.intValue()));
"SEQ_NAME" is name of the sequence defined in the database for the ID field
However, this portion of the code should be contained in the create(...) method of the entity object.
You need to tell JDeveloper to generate create(...) method for the entity object. This can be accomplished by checking "generate create method" check box in Java panel of entity object wizard.
Please let me know if this works

Similar Messages

  • Create trigger and use "nextval" to get next sequence nbr

    Hi i created a table and a primary key for that table as follows:
    create table PROD_TRNSLTN
    PROD_PK VARCHAR2(16),
    CNTRC_CD VARCHAR2(10),
    PROD VARCHAR2(10),
    PLN VARCHAR2(10)
    alter table PROD_TRNSLTN
    add constraint PROD_TRNSLN_PK primary key (PROD_PK);
    i then created a trigger to automatically populate the primary key
    create trigger PROD_TRNSLTN_TRGR
    before insert on PROD_TRNSLTN
    for each row
    begin
    Select PROD_PK.nextval into :new.PROD_PK from dual;
    end;
    i get no syntax error, but when i use SQLLoader to insert rows into this table i get:
    "ORA-04098: trigger 'IAVE.PROD_TRNSLTN_TRGR' is invalid and failed re-validation"
    Why??
    Edited by: aft5425 on Oct 30, 2008 11:37 AM

    Hi,
    So you can compile via your editor? It sounds handy, but if it doesn't show error messages, and it doesn't allow you to indent your code, it's not worth it.
    Save your code (as prod_trnsltn_trgr.sql):
    create trigger    PROD_TRNSLTN_TRGR
    before insert on  PROD_TRNSLTN
    for each row
    begin
        Select  PROD_PK.nextval
        into    :new.PROD_PK
        from    dual;
    end;
    SHOW ERRORSThe open SQL*Plus in a separate window and say
    SQL> @full_path\prod_trnsltn_trgrIf you can't fix the problem, post your code and all messages you get in SQL*Plus.

  • Read table to get next value (Sequence Question)

    Is there a function in line with my_seq_no.nextval that can read a value in the previous field and get the next sequence number? I know how to create a sequence, but I thought that there is something like a getnextval function.
    Thanks.

    Preston,
    The problem is that there is no such thing as a previous value in Oracle.
    You have to specify some way (like maximum number.. etc..) to get the expected value...
    Sometimes , you can see code like....
    insert into emp values
    (select max(empid) + 1 from emp) new_emp_id,
    ''XYZ' ename,
    from dual;As is evident...the above code takes the maximum value from the table emp and gives you the next emp id.
    The problem here is that all the currently logged in users will get the same value for the new empid until someone inserts a record and then.. all the others would have unique constraint errors (if you have the right constraints in place).
    Using sequences is the right way to make sure all the concurrent users get their own unique values for the new values.
    As for the getnextval, one could always come up with a function which just selects the max(col_name)+1 and returns it... but it has the same problems as the insert...select mentioned above.. So i would rather not provide code for such a thing.. I'd be doing more damage than help. Please use a sequence for your case.

  • Get next BusinessPartners Code/Key

    Hi together,
    I am looking for a way to get the next CardCode of a BusinessPartner to add a new one by DIApi.
    I tried it by using some Code like this, but it does not work fine:
    Dim oSeriesService As SAPbobsCOM.BusinessPartnersService = cmpService.GetBusinessService(SAPbobsCOM.ServiceTypes.BusinessPartnersService)
    Dim oSeriesCollection As SAPbobsCOM.BusinessPartners = oSeriesService.GetDataInterface(SAPbobsCOM.BusinessPartnersServiceDataInterfaces.bpsdiBPCodes)
    The Bold Text is not very fine, because there is no method like 'GetNextCardCode', otherwise its not tested, so i dont think this would work.
    Is there a way like the SeriesService... eg. there are no problems to get the next DocNum of an invoice
    Thank you!
    Sebastian

    I don't know if B1 has anything to generate a "next" cardcode value but I doubt it since the field is alphanumeric,
    but I've written something to do this for myself.
    On the before event when the user clicks on the add mode on the BP form, and if they leave the cardcode blank,
    I use a sql statement to determine the next number to assign.  We always prefix our customer numbers with a "C"
    and our Suppliers with a "V" so I look for the highest cardcode (max) out there where the first character is a c/v and
    the rest of the card code is completely numeric (like 'C1001', but not 'Customer 1' since it contains alpha values). 
    I just add one to the 1001 part and return 'C1002'.  If by chance two users end up assigning the same number,
    I let B1 catch the duplicate.
    Maybe this code will work for you:
    Public Enum BP_Type
            Customer = 0
            Vendor = 1
        End Enum
                    'in add mode, if user leaves cardcode empty, then assign it the next highest number from table
                    If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                        If Not IsNothing(cmbx) AndAlso Not IsNothing(cmbx.Selected) Then
                            Dim type As BP_Type
                            Dim prefix As String
                            If cmbx.Selected.Value = "S" Then
                                type = BP_Type.Vendor
                                prefix = "V"
                            Else
                                type = BP_Type.Customer
                                prefix = "C"
                            End If
                            If CardCode.Value = Nothing Then
                                Try
                                    CardCode.Value = GetNextCardCode(type, prefix)
                                Catch ex As Exception
                                    B1App.MessageBox("Could not generate next Card Code. " & vbCrLf & ex.ToString)
                        Bubble = false
                                End Try
                            End If
                        End If
                    End If
       Public Shared Function GetNextCardCode(Optional ByVal zCardType As BP_Type = BP_Type.Customer, Optional ByVal zCardCodePrefix As String = "C") As String
            Dim brwsr As Recordset
            Dim sql As String
            Dim cardtype As String
            'sql statement is looking for next number based on C or V in first character of existing cardcodes, via passed in
            'prefix field.
            Select Case zCardType
                Case BP_Type.Customer
                    cardtype = "C"
                Case BP_Type.Vendor
                    cardtype = "S"
            End Select
            'Get next highest customer number from table where customer number
            'starts with a C and the remainder of the value is numeric; then add one to the max value
            brwsr = oCompany.GetBusinessObject(BoObjectTypes.BoRecordset)
            sql = "select  COALESCE(cast(max(str(substring(cardcode,2,len(cardcode)-1))) as numeric) +1,1) " & _
            " as newcode from ocrd  where cardtype = '" & cardtype & "' and left(cardcode,1) = '" & zCardCodePrefix & "' AND isnumeric(substring(cardcode,2,len(cardcode)-1)) = '1'"
            brwsr.DoQuery(sql)
            Return zCardCodePrefix & brwsr.Fields.Item("newcode").Value
        End Function
    HTH

  • How to get selected sequence in a file

    Hello,
        I can get the selected sequence file by accessing the RunState.InitialiSelection.SelectedFile property. However, if i want to get the name of the sequence that was selected in this sequence file, then how can i get that?
    Thanks,
    Regards,
    Aparna

    Hello,
       Sorry, i saw this thread a little late. My question is still the same. The solution that you gave actually gives me the display name of the sequence file. But i wanted the name of the sequence that was opened withtin the sequence file. Here is what i have.
    A sequence file named TestExport.seq has two sequences  - MainSequence and SecondSequence. I open up the sequence file and open the SecondSequence in that file. But i dont know how to get this information about the sequence that is selected within the file. I have an external dll, in which i am passing the sequence file name as RunState.InitialSelection.SelectedFile. But i do not know how to get the sequence name that was actually opened in that file. Because i actually want to get the sequence context of the sequence within the file. The code that i have looks like this:
    public ExportDlg(SequenceFile seqFile)
                InitializeComponent();
                SequenceContext seqContext = seqFile.NewEditContext();
                engine = seqContext.Engine;
                object outParam = System.Type.Missing;
                this.seqContext = engine.NewEditContext(seqFile.GetSequence(0).AsPropertyObject(),System.Type.Missing,out outParam);
    seqFile.GetSequence(0) - gives me the context of the first sequence which is MainSequence. But if i have opened the SecondSequence, i need the context for that. And to get this, i need the sequence name "SecondSequence" somehow.
    RunState.InitialState.SelectedSequences is an array of containers. Although i can see the sequence name during executing, i do not know how to get the name of the container my external dll .
    Please help,
    Thanks,
    Regards,
    Aparna

  • Minimum VisualC++ source code to execute a sequence

    Hello,
    I need to make a small applet that will call TestStand sequence.
    It has to initialize engine, run sequence, exit and return exit code of error or success.
    No user interaction is needed/wanted. So I dont want to compile file with MFC or ATL libraries.
    Theoreticaly I can initialize and run COM object even from console application, but in practice - I'm not sure, which interfaces should I call.
    Maybe it should start like:
    CoInitialize(NULL); // Init COM
    IEnginePtr pEngine (__uuidof(TS::Engine), NULL, CLSCTX_ALL); // get the pointer to interface
    pEngine->PutUIMessageMinDelay(0); // do some calls
    pEngine->LoadTypePaletteFiles();
    CoUninitialize(); // Unitializing COM
    Is it a rig
    ht/possible way to do it?
    Will I get some problems later if I will use such method?
    Thank you!

    You can discern the minimal code required to execute a sequence from the "SimpleMFCOperatorInterface" in your \Examples\OperatorInterfaces\Simple MFC directory. You are correct in that you do not have to use MFC or ATL in order to load the TestStand engine and execute a sequence, the only requirements are as follows (as well as the general process flow of loading the engine and executing a sequence):
    1) Initialize the COM library with OleInitialize()
    2) Create an instance of the TS engine with TS::IEnginePtr CreateInstance()
    3) Register your UIMessageCallback function with TS::IEngine RegisterUIMessageCallback(). Your UIMessageCallback function should have a structure similar to this:
    void __cdecl UIMessageCallback(struct IDispatch *UIMessageDisp)
    TS::UIMessagePtr uimsg = UIMessageDisp;
    TS:equenceContextPtr seqcontext;
    int hr;
    seqcontext = uimsg->Thread->GetSequenceContext(0,NULL);
    switch((int)uimsg->Event)
    case 0:
    break;
    case 8:
    hr = seqcontext->Engine->ShutDown(VARIANT_FALSE);
    break;
    case 9:
    hr = seqcontext->Engine->ShutDown(VARIANT_TRUE);
    quit = true;
    break;
    default:
    break;
    return;
    NOTE: You must handle the "EndExecution" and "ShutdownComplete" UIMessages (eventcodes 8 and 9 respectively) at a minimum in order to properly execute a sequence and shutdown the engine when it is complete.
    4) Get a sequence file reference with TS::IEngine GetSequenceFile() (note: you can use the TS::IEngine DisplayOpenFileDialog() method to select a file path with)
    5) Start the execution with TS::IEngine NewExecution()
    NOTE: That the above UIMessageCallback message handler waits for the "ShutdownComplete" message to set a flag variable named "quit" to true to signify to the rest of the application that the sequence has finished executing.
    If you take a look at the source files for the SimpleMFCOperatorInterface, you can see how each of these methods are used.
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask

  • Sample code to get 1st 5 characters of a field and also how to use help ?

    hi ABAP4 experts,
    We are kind of new at ABAP4. We'd be appreciated if you would provide sample code to get 1st 5 characters of a field and also let us know on how to use ABAP4 help to look for such kind solution that next time we don't have to bother you guys here!
    We will give you reward points!
    Message was edited by: Kevin Smith

    Hi Kevin,
    here is the Example for the offset which you want
    DATA TIME TYPE T VALUE '172545'.
    WRITE TIME.
    WRITE / TIME+2(2).
    CLEAR TIME+2(4).
    WRITE / TIME.
    <u>The output appears as follows:</u>
    172545
    25
    170000
    <i>First, the minutes are selected by specifying an offset in the WRITE statement. Then, the minutes and seconds are set to their initial values by specifying an offset in the clear statement.</i>
    <b>2nd Example:-</b>
    DATA: F1(8) VALUE 'ABCDEFGH',
    F2(8).
    DATA: O TYPE I VALUE 2,
    L TYPE I VALUE 4.
    MOVE F1 TO F2.      WRITE F2.
    MOVE F1+O(L) TO F2.      WRITE / F2.
    MOVE F1 TO F2+O(L). WRITE / F2.
    CLEAR F2.
    MOVE F1 TO F2+O(L). WRITE / F2.
    MOVE F1O(L) TO F2O(L). WRITE / F2.
    This produces the following output:
    ABCDEFGH
    CDEF
    CDABCD
      ABCD
      CDEF
    First, the contents of F1 are assigned to F2 without offset specifications. Then, the same happens for F1 with offset and length specification. The next three MOVE statements overwrite the contents of F2 with offset 2. Note that F2 is filled with spaces on the right, in accordance with the conversion rule for source type C.
    if you want more info
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb341a358411d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3294358411d1829f0000e829fbfe/content.htm
    hope this solves your Problem
    Thanks
    Sudheer

  • Actionscript help needed with getting Next Page to work

    I just have a simple question (hopefully).
    Question is:
    I have a web page that displays a flash file that zooms and
    pans, but I cant get the Next Page link to display. (will also want
    1st, last and previous page)
    1. Can the next page work and load the next or previous
    numbered file?
    2. Does it have to have all pages in one file, then it calls
    the next frame?
    Snippet below, or I can e-mail example files.
    Please help, Thank you, Mike
    ============SNIPPET==========
    <!--[if IE]>
    <object id="movie" type="application/x-shockwave-flash"
    width="300" height="500">
    <param name="movie" value="1.swf">
    </object>
    <![endif]--><!--[if !IE]> <-->
    <embed name="movie" type="application/x-shockwave-flash"
    src="1.swf" width="300" height="500">
    </embed>
    <!--> <![endif]-->
    <form name="f" onsubmit="return false;">
    <button name="button" onclick="next()">Next
    Page</button>
    <button onclick="zoom()">Zoom In</button>
    <button onclick="zoom2()">Zoom Out</button>
    <button onclick="pan()">Pan</button>
    <button onclick="setzoomrect()">Rect</button>
    </form>
    function next() {
    var flash = window.movie || document.movie; // Get Flash
    object.
    flash.Zoom(50);

    Use the same method you are currently using. The Zoom and Pan
    methods just happen to be exposed to the ActiveX control and
    Plug-in. So to use the the GotoFrame() method for example, just
    change your code from:
    function next() {
    var flash = window.movie || document.movie; // Get Flash
    object.
    flash.nextpage();
    To this:
    function next() {
    var flash = window.movie || document.movie; // Get Flash
    object.
    flash.GotoFrame(20); // This will jump to frame 19 of your
    main timeline.
    It goes to frame 19 because the method you are using is
    zero-based. Meaning to get to the first frame of your movie you
    would pass the number zero.
    To use the TCallLabel() method it would look like this:
    function next() {
    var flash = window.movie || document.movie; // Get Flash
    object.
    // to target the main timeline, use
    flash.TCallLabel("/", "labelName");
    // to target a movieclip on the main timeline use:
    flash.TCallLabel("/MovieClip", "lableName");
    Also, just so you know. These methods are getting antiquated.
    To keep up with the current versions and methods of communicating
    between JS and Flash you should really look into the
    ExternalInterface class in Flash 8.
    Tim

  • HT3209 Purchased a blu ray with a code to get a digital says it is invalid

    I recently purchased a Blu Ray that came with code to get a free digital copy of the movie, when I typed in the code it said it was invalid

    I am assuming the reason it is not compatible with my i pod is because it is a HD copy of the film.
    That is correct.
    Head to the iTunes Store, click the Purchased link on the right, and then select Movies and remove the tick mark next to Download HD when available.  You might be able to download the SD version now from under this same page. Any luck there?
    B-rock

  • How to get generated sequence number from JPA/TopLink

    Hi there,
    I am using JDev 10.1.3.3 with JPA + POJO + TopLink.
    In the entity (POJO), I declared a sequence generated for a number field.
    @Id
    @GeneratedValue(strategy=SEQUENCE, generator="GEN_CUSTOMER_ID_SEQ")
    @SequenceGenerator(name="GEN_CUSTOMER_ID_SEQ", sequenceName="CUSTOMER_ID_SEQ", allocationSize=1)
    @Column(name="CUSTOMER_ID", nullable = false, precision = 12 )
    private Long customerId;
    In my program, I don't need to set the Id field because it is set automatically.
    However, I want to get the generated sequence using code. Is there a way?
    Thanks,
    Jim
    P.S. I cannot use getCustomerId because the value has not been set yet.

    If you call persist on the new Entity, or flush() the id will be assigned, and you can get it.
    There is also an API on the TopLink / EclipseLink Session getNextSequenceNumberValue(), that you can use to get a sequence value.
    -- James: http://www.eclipselink.org

  • Creating next sequence

    I need to insert a record into a table that does not have a sequence object. The table contains system user types.
    DESC USER_TYPE
    Name                           Null     Type                                                                                                                                                                                         
    USER_TYPE_ID                   NOT NULL NUMBER                                                                                                                                                                                       
    USER_TYPE                               VARCHAR2(100)                                                                                                                                                                                
    USER_TYPE_PID                           NUMBER                                                                                                                                                                                       
    ABBR                                    VARCHAR2(15) There are 100,000 records.
    When I try the following an error displays:
    CREATE SEQUENCE USER_TYPE_ID_SEQ
    INSERT INTO user_type(USER_TYPE_ID,USER_TYPE,USER_TYPE_PID,ABBR) VALUES(USER_TYPE_ID_SEQ.nextval,'UNASSIGNED',NULL,NULL)
    Error report:
    SQL Error: ORA-00001: unique constraint (DEV_FIRM_CCB.USER_TYPE_USER_TYPE_ID_PK) violated
    00001. 00000 - "unique constraint (%s.%s) violated"
    Where the USER_TYPE_USER_TYPE_ID_PK is column USER_TYPE_ID.
    How can I start the next sequence from the max value of USER_TYPE_ID(100,000).
    Something like this:
    CREATE SEQUENCE USER_TYPE_ID_SEQ START WITH (SELECT INTEGER(MAX(USER_TYPE_ID)+ 1) FROM USER_TYPE)
    But this does not work. Any help is appreciated.

    achtung wrote:
    Assuming nobody is inserting into user_type table while you run the code:
    declare
        v_stmt varchar2(1000);
    begin
        select  'create sequence user_type_id_seq start with ' || max(user_type_id)
          into  v_stmt
          from  user_type;
        execute immediate v_stmt;
    end;
    /SY.
    P.S. Table name USER_TYPE is a poor choice - too close to data dictionary view name USER_TYPES.

  • I bought Adobe Photoshop Elements 13 from wal mart today, and when i go to type in my redemption code to get my serial number it says my redemption code is invalid? and yes i have done it with caps and without caps, ive tried everything and I dont know wh

    I bought Adobe Photoshop Elements 13 from wal mart today, and when i go to type in my redemption code to get my serial number it says my redemption code is invalid? and yes i have done it with caps and without caps, ive tried everything and I dont know what to do anymore. I know its non returnable once opened and the package wasnt tampered with when I bought it. im at a loss on what to do

    Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html
    -and https://forums.adobe.com/thread/1572504
    Lost serial # http://helpx.adobe.com/x-productkb/global/find-serial-number.html

  • HT1539 I put in the code to get game of thrones season 2, says it's downloading. yet the downloader is empty and doesn't seem to download anything. I got to game of thrones page in itunes and it's asking for money to download the episodes. what is going o

    I used my code to get my season 2 of game of thrones on itunes.  I got a message stating I successfully redeemed my code and my season is downloading...
    Yet there is nothing in my downloader and when I go to game of thrones season 2 to download episode it is asking for money.  What did I do wrong?

    See Empty/corrupt library after upgrade/crash.
    tt2

  • T-codes to get payment run report for different company codes?

    Hello sap gurus,
    I have a scenario like -
    > use of IDocs to process vendor and employee payments. Both bank transfers and checks will be processed through interface.
    Now, What is the t-code to get report for payments for different customer, comp codes and vendor?
    I am new to SAP in testing.
    Appreciate ur help......
    Regards,
    Shamsher
    Edited by: shamsher123 on Jun 4, 2010 11:52 AM

    Hello,
    See the List below hope this will help.
    MIR5 - Display List of Invoice Documents
    S_ALR_87012105 - List of Down Payments Open On Key Date - Vendors
    S_ALR_87012085 - Vendor Payment History with OI Sorted List
    S_P99_41000099 - Payment List
    Prashant Rathore.

  • Error in Get Next Non-Text Sibling for XML without CR at end of tag

    Hallo all,
    I'm having a strange error parsing XML files with labview. I have an XML file in one single line, without CR at end of each tag. A normal browser or XML parsing tool is capable to read it, but not with Labview.
    The error I have is with "Get Next Non-Text Sibling.vi", which internally fails to read Type property (Error -2630, Property Node (arg 1) in NI_XML.lvlib:Get Next Non-Text Sibling.vi->XML Get Siblings Childs Nodes.vi->Encode data to label (Path).vi).
    Labview XML parser works if I add a CR at each tag/node.
    I'm quite sure this is a labview bug. A workaround I have found is to open the file, then save the file with Save File (Pretty Print) method and reopen it again, but it is time-consuming and I would like to avoid it.
    Regards,
    Daniele
    Solved!
    Go to Solution.
    Attachments:
    xmlwithnoCR.xml.txt ‏1 KB

    Which node do you pass to XML Get Siblings Child Nodes.vi ? That is also important.
    I can imagine the following scenario causing your problem: Your input node has a child node C,, but this child node has no siblings. Get Next Non-Text Sibling.vi will fail in this case. If you put a <CR> at the right position in your XML you create a text node with content <CR>. If this text node is a sibling of child C then Get Next Non-Text Sibling.vi still won't return anything but no error should occur. IMHO this is expected behavior. You can however implement your own version of Get Next Non-Text Sibling.vi. Use the Next Sibling property and check if it returns a valid refnum.

Maybe you are looking for

  • Print button is not visible in RDLC report

    hi I am developing web application in Visual studio 2012 ,.net framework 4.5,C#.net I have designed RDLC report for web application,in report viewer i have given showprint button = true, in browser print is not visible in all the browser. How should

  • Can't access suggestions in Google toolbar dropdown since upgrading to F4.Suggestions appear but when I click on one nothing happens.

    Can't access suggestions in Google toolbar dropdown since upgrading to F4.Suggestions appear but when I click on one nothing happens - it just returns to what I've typed already. eg If I type the word 'honey' a number of suggestions appear. One is 'h

  • Previous button clears my online form...

    I'm using MIE 9 and I have created a form of 5 pages. when I want to see my answers for example on the first page and i hit previous to go back the form clears it self... Is this still the same problem as here? http://forums.adobe.com/message/4434484

  • Before updating to Maverick?

    i dont have a external HD do i need to do  complete  external back up of my Imac HD before updating to maverick? is it risky to loose some date if not doing it Imac 2,4 Ghz intel core 2 duo 2 Go RAM running on 10,6,8 thanks

  • Ant and remote J2EE engine

    Hi all, When "ant init" running, is it possible to enter path to remote J2EE Engine, instead of 'c:\usr\sap\...'? Or, is there another way to use remote J2EE Engine? Regards, Roman Babkin