Skip to main content
August 20, 2008
Question

Need Order ID Number Creator

  • August 20, 2008
  • 3 replies
  • 554 views
Employer wants an Order number starting with I and haveing 6-8 characters in. So for example first order would be I000601. Anyone have any ideas of scripts or items that would create this. Need to make sure that it doesn't duplicate. I know CreateUUID would be perfect for this but it is way too long. Suggestions.
    This topic has been closed for replies.

    3 replies

    Inspiring
    August 20, 2008
    Try something similar with an application variable.
    Inspiring
    August 20, 2008
    quote:

    Originally posted by: Dan Bracuk
    Try something similar with an application variable,
    or a small table that you select from and increment



    Inspiring
    August 20, 2008
    If you are using oracle, you could create a sequence starting at 601. Then you can pad it with zeros and prepend the letter I.
    August 20, 2008
    Not using oracle but thanks for the idea.
    Inspiring
    August 20, 2008
    PopcornCoder wrote:
    > Employer wants an Order number starting with I and haveing 6-8 characters in.
    > So for example first order would be I000601. Anyone have any ideas of scripts
    > or items that would create this. Need to make sure that it doesn't duplicate.
    > I know CreateUUID would be perfect for this but it is way too long.

    > Suggestions.

    That's fine, what are the rest of the business rules? I.E. are these
    random numbers or sequential, etc.

    Otherwise this is just basic logic and string manipulation probably
    combined with a look up of existing recorded order numbers to ensure
    uniqueness.

    A super basic example.

    <cfscript>
    i = randRange(1,99999999);
    invoiceNum = 'I' & replace(rJustify(i,6),' ','0','ALL');
    writeOutput(invoiceNum);
    </cfscript>
    August 20, 2008
    Prefer sequential and starting at the I000601 number
    Inspiring
    August 24, 2008
    Building on Dan's last suggestion, using a small table with increment,
    try the following it should work for you.

    This method will also let you reset the number should that be necessary.

    <cfquery name="rs_order_number" datasource="dsn">
    SELECT order_number
    FROM order_number
    </cfquery>

    <cfquery name="update_order_number" datasource="dsn">
    UPDATE order_number
    SET order_number = order_number + 1
    </cfquery>

    <cfset order_number = "I#NumberFormat(rs_order_number.order_number,00000000)#">

    <cfoutput>#order_number#</cfoutput>

    Leonard B