Creating Orders from PO
This API creates a sales order from a Customer Purchase Order: single order, multiple order using split criteria, or partial order.
API Details
| API | Signature | 
|---|---|
| createOrderForPO | 
                            | 
| Parameter 1: Create Order for Customer Purchase Order Data Object | ||
|---|---|---|
| Name | Type | Description | 
| request | 
 | The request data object. | 
| Request Data Object - CreateOrderForPORequestDO | ||
|---|---|---|
| Field | Type | Description | 
| orderInputSO | 
 | To create the order inputs. | 
| PurchaseOrderId | 
 | To create a single order. | 
| SplitGroupFields | 
 | To group by orders | 
| Request Standard Object - orderInputSO | |||
|---|---|---|---|
| Field | Type | Required? | Description | 
| SoldToAccountId | 
 | Yes | The id of the Account to which the order is placed. | 
| PriceListId | 
 | Yes | The id of the PriceList to be associated with the order. | 
| PricingDate | 
 | No | Date and time associated with the order and represent the date when the order will be priced. | 
| OrderDate | 
 | No | Date and time when the order is created. | 
| OrderStartDate | 
 | No | Date and time when the order fulfillment starts. | 
| OrderEndDate | 
 | No | Date and time when the order fulfillment ends. | 
| useAdvancedApproval | 
 | No | Whether to use advanced approval. The default value is False. | 
| useDealOptimizer | 
 | No | Whether to use the Deal Optimizer. The default value is False. | 
| Parameter 2: Create Selected Purchase Order Item Data Object | ||
|---|---|---|
| Name | Type | Description | 
| request | 
 | The request data object. | 
| Request Data Object - poItemDO (Required for partial order only) | |||
|---|---|---|---|
| Field | Type | Required? | Description | 
| POItemId | 
 | Yes | Customer PO item number. | 
| ProductId | 
 | Yes | Customer Product item number. | 
| Quantity | 
 | Yes | Quantity of the order. | 
| StartDate | 
 | No | Date and time when the PO fulfillment starts. | 
| EndDate | 
 | No | Date and time when the PO fulfillment ends. | 
| Selling Term | 
 | No | Duration of the customer PO. | 
| Comments | 
 | No | Any notes. | 
| SourceId | 
 | Yes | Source ID of the order. For example, Quote, Contract, or Agreement ID. | 
| Comments | 
 | No | Comments about the agreement. | 
| ContractNumbers | 
 | No | Contract number from the agreement. | 
API Response
| Response Data Object - Apttus_CPQApi.CPQ.CreateOrderForPOResponseDO | ||
|---|---|---|
| Name | Type | Description | 
| OrderId | 
 | 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);
   
