Microsoft KB Archive/172662

= INF: How To Create a Shorter Order ID =

Article ID: 172662

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Commerce Server 2.0

-



This article was previously published under Q172662



SUMMARY
Microsoft Commerce Server 2.0 creates a 26 character order ID for each shopper's order. This order ID is a Globally Unique Identifier (GUID) generated by the Windows NT system, and is difficult for hackers to guess. However, some merchants have a requirement to create and save a shorter order ID. This article describes ways to generate shorter order IDs.



Put Your Own Format Order ID on the Order Form When It Is Initially Created
One way to create shorter IDs is to put your own format order ID onto the order form when it is initially created. When the order pipeline runs normally, no order_id name/value-pair exists, so Commerce Server creates one. If the order_id name/value-pair already exists, Commerce Server does not attempt to overwrite it.

To do this, perform the following steps:   Create a database table that holds the last assigned order_id. Create a stored procedure that fetches the next order ID to be assigned, and remembers it as the last assigned order_id. For example, the following Microsoft SQL Server script does this for the ClockPed store: /*  * Create a table to hold the last assigned order number. Seed it at 100. *  */

drop table ClockPed_ordernumber go

create table ClockPed_ordernumber(     order_id int) go

INSERT ClockPed_ordernumber VALUES (100) go

drop proc sp_CPgetorderid go  CREATE PROCEDURE sp_CPgetorderid @ide int = 0 AS  UPDATE ClockPed_ordernumber SET next_order_id = next_order_id+1, @ide = next_order_id SELECT @ide order_id go                         Update the xt_orderform_additem.asp page to invoke the stored procedure and save the order_id onto newly created order forms. Again, in ClockPed, this would be something like the following: if IsEmpty(orderForm) then REM -- create a new orderform: set orderForm = Server.CreateObject("Commerce.OrderForm") orderForm.shopper_id = shopperID orderForm.date_created = Now

REM Retrieve the next available order_id number from the database REM on error resume next set o_id = MSCSDataSource.Execute("EXEC sp_CPgetorderid")(0) on error goto 0 if Not IsEmpty(o_id) then orderForm.order_id = o_id.order_id end if

REM -- add item to orderform: set item = orderForm.AddItem(CStr(product_sku), product_qty, 0) 

Create a New Column in the Database Table that Holds the Order Information
If you want a shorter order_id for the convenience of a shopper, you can create a new identity column in the database table that holds the order information. This column would be incremented automatically by SQL Server, whenever an order is saved to the database. You can then retrieve the identity column value that corresponds to a given order_id generated by Commerce Server, and display it to the shopper on your purchase confirmed page.

To do this, perform the following steps:  Alter your receipt table to contain a new identity column. The following SQL Server script alters the vc_receipt table of the Volcano Coffee store: delete from vc_receipt go alter table vc_receipt add NewOrder_ID int identity  Modify the Confirmed.asp file to include the following: <% OrderID = Request("order_id") set test = DataSource.Execute("select neworder_id from vc_receipt where  order_id = :1",  OrderID)(0) %>

For future reference, please make a note of the tracking number for this order.</TR> <TR> </TD></TR> <TR><img src="<% =Application("Images") %>images/trackno.gif" valign=bottom> <b> <% = test.neworder_id %> </b> </TD> </TR> </li></ol>

Additional query words: orderform orderforms Merchant

Keywords: kbhowto kbinfo kbprogramming kbusage KB172662

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.