This API creates a sales order from a Customer Purchase Order: single order, multiple order using split criteria, or partial order. 

You must enable the Split Group Properties field on the PO item in order to consume this functionality. Refer to the Order Management for Administrators for steps.

API Details

APISignature
createOrderForPOwebService static Apttus_CPQApi.CPQ.CreateOrderForPOResponseDO createOrderForPO(Apttus_CPQApi.CPQ.CreateOrderForPORequestDO)
Parameter 1: Create Order for Customer Purchase Order Data Object
NameTypeDescription
request

Apttus_CPQApi.CPQ.CreateOrderForPORequestDO

The request data object.
Request Data Object - CreateOrderForPORequestDO
FieldTypeDescription

orderInputSO

Standard ObjectTo create the order inputs.

PurchaseOrderId

IDTo create a single order.

SplitGroupFields

List<String>To group by orders



Request Standard Object - orderInputSO
FieldTypeRequired?Description
SoldToAccountIdIDYesThe id of the Account to which the order is placed.
PriceListIdIDYesThe id of the PriceList to be associated with the order.
PricingDateDatetimeNoDate and time associated with the order and represent the date when the order will be priced.
OrderDateDatetimeNoDate and time when the order is created.
OrderStartDateDatetimeNoDate and time when the order fulfillment starts.
OrderEndDateDatetimeNoDate and time when the order fulfillment ends.

useAdvancedApproval

BooleanNoWhether to use advanced approval. The default value is False.

useDealOptimizer

BooleanNoWhether to use the Deal Optimizer. The default value is False.
Parameter 2: Create Selected Purchase Order Item Data Object
NameTypeDescription
request

Apttus_CPQApi.CPQ.SelectedPOItemDO poItemDO

The request data object.
Request Data Object - poItemDO (Required for partial order only)
FieldTypeRequired?Description
POItemIdIDYesCustomer PO item number.
ProductIdIDYesCustomer Product item number.
QuantityIntegerYesQuantity of the order.
StartDateDatetimeNoDate and time when the PO fulfillment starts.
EndDateDatetimeNoDate and time when the PO fulfillment ends.
Selling TermIntegerNoDuration of the customer PO.
CommentsTextNoAny notes.
SourceIdIDYesSource ID of the order. For example, Quote, Contract, or Agreement ID.
CommentsTextNoComments about the agreement.
ContractNumbersTextNoContract number from the agreement.

API Response

Response Data Object - Apttus_CPQApi.CPQ.CreateOrderForPOResponseDO
NameTypeDescription

OrderId

ID

Order number which is created for customer PO.

Code Sample

String ACCOUNT_NAME = 'RY_Account_002';
String PRICELIST_NAME = 'RY_PriceList';
Integer SELLING_TERM = 12;
Id CUSTOMER_PO_ID = 'a440R0000002Tif';
String SPLIT_ORDER_FIELD = 'RY_GroupingTest__c';
Id PO_ITEM_ID = 'a430R000000O2tC';
Id SOURCE_ITEM_ID = 'a0W0R000000JT9F';

Account myAccount = [SELECT Id FROM Account WHERE Name =: ACCOUNT_NAME];
Apttus_Config2__PriceList__c myPriceList = [SELECT Id FROM Apttus_Config2__PriceList__c WHERE Name =: PRICELIST_NAME];
Apttus_Config2__CustomerPOItem__c poItem = [SELECT Id, RY_GroupingTest__c, Apttus_Config2__ProductId__c, Apttus_Config2__Quantity__c, Apttus_Config2__StartDate__c, Apttus_Config2__EndDate__c FROM Apttus_Config2__CustomerPOItem__c WHERE Apttus_Config2__PurchaseOrderId__c =: CUSTOMER_PO_ID AND Id =: PO_ITEM_ID LIMIT 1];


/* 

Create Order for Customer Purchase Order Data Object */
Apttus_CPQApi.CPQ.CreateOrderForPORequestDO request = new Apttus_CPQApi.CPQ.CreateOrderForPORequestDO();

// Create the Order Input
Apttus_Config2__Order__c orderInputSO = new Apttus_Config2__Order__c();

orderInputSO.Apttus_Config2__SoldToAccountId__c = myAccount.Id;
orderInputSO.Apttus_Config2__PriceListId__c = myPriceList.Id;
orderInputSO.Apttus_Config2__PricingDate__c = Datetime.now();
orderInputSO.Apttus_Config2__OrderDate__c = Datetime.now();
orderInputSO.Apttus_Config2__OrderStartDate__c = Date.today();
orderInputSO.Apttus_Config2__OrderEndDate__c = Date.today().addMonths(SELLING_TERM);
request.OrderInput = orderInputSO;



// Add Order Properties (Optional)
request.Properties.add(new Apttus_Config2.Property('useAdvancedApproval', 'false'));
request.Properties.add(new Apttus_Config2.Property('useDealOptimizer', 'false'));



// Assign the Customer Purchase Order (For single order)
request.PurchaseOrderId = CUSTOMER_PO_ID;



// Add Order Items (Optional)

// Selecting Items
// Create Selected Purchase Order Item Data Object

Apttus_CPQApi.CPQ.SelectedPOItemDO poItemDO = new Apttus_CPQApi.CPQ.SelectedPOItemDO(); (For partial order)

//webService Apttus_Config2__LineItem__c CustomData
//webService List CustomFields

poItemDO.POItemId = poItem.Id;
poItemDO.ProductId = poItem.Apttus_Config2__ProductId__c;
poItemDO.Quantity = poItem.Apttus_Config2__Quantity__c;
poItemDO.StartDate = poItem.Apttus_Config2__StartDate__c;
poItemDO.EndDate = poItem.Apttus_Config2__EndDate__c;
poItemDO.SellingTerm = Apttus_Config2.CPQWebService.computeTerm(poItemDO.StartDate,poItemDO.EndDate,'Monthly');
poItemDO.Comments = 'Purchase order item test';
    


// Set Additional Parameters From Source Line Item
poItemDO.SourceId = SOURCE_ITEM_ID;
poItemDO.SourceFields.add('Apttus_QPConfig__Comments__c');
poItemDO.SourceFields.add('Apttus_QPConfig__ContractNumbers__c');
request.OrderItems.add(poItemDO);



// Split Order Criteria 
//request.SplitGroupFields.add(SPLIT_ORDER_FIELD); (For group by orders)



// Create the Order(s)
Apttus_CPQApi.CPQ.CreateOrderForPOResponseDO result = Apttus_CPQApi.CPQWebService.createOrderForPO(request);
system.debug('Order Id = ' + result.OrderId);


CODE