USP_SALESORDER_ADD_ORDERCREATE

The save procedure used by the add dataform template "Add Sales Order".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@SALESMETHODTYPECODE tinyint IN Sales Method
@CONSTITUENTID uniqueidentifier IN Constituent ID

Definition

Copy


CREATE procedure dbo.USP_SALESORDER_ADD_ORDERCREATE
(
    @ID uniqueidentifier = null output,
    @CHANGEAGENTID uniqueidentifier = null,
    @SALESMETHODTYPECODE tinyint,
    @CONSTITUENTID uniqueidentifier = null
)
as

set nocount on;

--Book Lab says ?Specifically, the stored procedure is responsible for: Creating a new ID for the row we are going to insert (using the ?newid? function) and assigning it to the output ID parameter?.  

--But I think it has to accept a suggested ID and use it--the design of BBMetalWeb has the AddForm constructor creating one.

if @ID is null 
    set @ID = newid()

if @CHANGEAGENTID is null  
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

begin try
    insert into dbo.SALESORDER
    (
        ID, 
        ADDEDBYID, 
        CHANGEDBYID, 
        DATEADDED, 
        DATECHANGED,
        SALESMETHODTYPECODE,
        CONSTITUENTID
    )
    values
    (
        @ID,
        @CHANGEAGENTID
        @CHANGEAGENTID
        @CURRENTDATE
        @CURRENTDATE,
        @SALESMETHODTYPECODE,
        @CONSTITUENTID 
    )
end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0