Consumer Support in TSM Product order and Service Order
Business Requirement: -
Some of the clients / customer may have a B2C model. Where the consumer can use external system to submit the orders.
In such cases they may not use Account / customer fields on the customer Order forms but rather they would like to go with the consumer field which is available on the sn_ind_tmt_orm_order table but as OOTB business logic in TSM the consumer support is not provided.
The FLOW logic or the model developed by the ServiceNow is that you can either use consumer or customer(account) on the Order (updated manually). i.e. you will not be able to consume the Open API without customer details.
Below is the example(error) shown when you will try to consume API without customer or with consumer.
But here, we do not require the customer Account as we are trying to use Consumer.
Custom Solution: -
As of now with current San Diego release there is no support for consumer as OOTB flow or business requirement. Hence, we would need to go with the custom solution by extending the OOTB classes.
Below is the step-by-step procedure to update the required application files:
- Consumer Support for Service Orders
Please follow below steps to get generate the service orders with Consumer.
Note: - Consumers should be already setup in the system so that they can be sent via payload(relatedParty) using Open API.
- Create a copy of ‘TMFOrderAPIConstants’ script include. Save it with new name (e.g. - TMFNewOrderAPIConstants).
- Add below lines of code in the newly created Include.
- CONSUMER_REFFERED_TYPE = 'Consumer';
- MISSING_CONSUMER_ACCOUNT: 'Invalid payload: Consumer is missing',
- CREATE_CONSUMER_SERVICE_ORDER: "{\"title\":\"ServiceOrder\",\"type\":\"object\",\"properties\":{\"relatedParty\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"@referredType\":{\"type\":\"string\"}},\"reference\":[{\"referenceKey\":\"id\",\"table\":\"csm_consumer\",\"field\":[\"sys_id\",\"sn_ind_tsm_core_external_id\"],\"errorMsg\":\"Invalid payload: Consumer does not exist\",\"referenceCondition\":{\"conditionKey\":\"@referredType\",\"conditionValue\":\"Customer\",\"conditionOperator\":\"==\"}}],\"required\":[\"id\",\"@referredType\"]}},\"serviceOrderItem\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"action\":{\"type\":\"string\"},\"service\":{\"type\":\"object\",\"properties\":{\"serviceCharacteristic\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}},\"required\":[\"name\"]}},\"serviceSpecification\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"}},\"required\":[\"id\"],\"reference\":[{\"referenceKey\":\"id\",\"table\":\"sn_prd_pm_service_specification\",\"field\":[\"sys_id\",\"external_id\"],\"errorMsg\":\"Invalid payload: Service Specification does not exist\"}]}}},\"orderRelationship\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"relationshipType\":{\"type\":\"string\"}},\"required\":[\"id\",\"relationshipType\"]}}},\"required\":[\"id\",\"action\",\"service\"]}}},\"required\":[\"serviceOrderItem\"]}",
- CONSUMER_REFFERED_TYPE = 'Consumer';
Note: - above lines of code should be added at appropriate location by analyzing the sections.
- You need to extend the functions from ServiceOrderExtensionOOB in the ServiceOrderProcessor (i.e. – you need to override the functions and call the new include created so that Consumer schema is called.)
- So, add below functions in the ServiceOrderProcessor script include below line (// Define overriding functions here).
transformOrderGr: function(requestObject, orderGr) {
var relatedPart = requestObject.relatedParty;
if (!gs.nil(relatedPart)) {
for (var i = 0; i < relatedPart.length; i++) {
if (relatedPart[i]['@referredType'] == 'Consumer') {
orderGr.consumer = relatedPart[i].id;
} }
return orderGr;
} },
transformOrdLineItemGr: function(orderLineItem, orderGr, ordLineItmGr) {
ordLineItmGr.consumer = orderGr.getValue('consumer');
return ordLineItmGr;
},
validateRelatedPartyObj: function(orderObject, details) {
if (gs.nil(orderObject.relatedParty) || orderObject.relatedParty.length == 0)
return true;
for (var j = 0; j < orderObject.relatedParty.length; j++)
if (orderObject.relatedParty[j]['@referredType'] == "Consumer" || orderObject.relatedParty[j]['@referredType'] == TMFOrderAPIConstants.CUSTOMER_REFFERED_TYPE) {
return true;
} },
getServiceOrderSchema: function() {
return JSON.parse(sn_ind_tmt_orm.TMFNewOrderAPIConstants.SCHEMA.CREATE_CONSUMER_SERVICE_ORDER);
},
Example screenshot-
Now you can generate the JSON for your Service Order and consume it via Open API under REST Explorer. Sample JSON is as below.
- Consumer Support for Product Orders
Please follow below steps to get generate the product orders with Consumer.
Note: - Consumers should be already setup in the system so that they can be sent via payload(relatedParty) using Open API.
- Now that we have already modified the script Include “TMFOrderAPIConstants”, we just must add new schema for product order like we added for service order.
CREATE_CONSUMER_PRODUCT_ORDER: "{\"title\":\"ProductOrder\",\"type\":\"object\",\"properties\":{\"relatedParty\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"@referredType\":{\"type\":\"string\"}},\"reference\":[{\"referenceKey\":\"id\",\"table\":\"csm_consumer\",\"field\":[\"sys_id\",\"sn_ind_tsm_core_external_id\"],\"errorMsg\":\"Invalid payload: Consumer does not exist\",\"referenceCondition\":{\"conditionKey\":\"@referredType\",\"conditionValue\":\"Customer\",\"conditionOperator\":\"==\"}}],\"required\":[\"id\",\"@referredType\"]}},\"productOrderItem\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"action\":{\"type\":\"string\"},\"product\":{\"type\":\"object\",\"properties\":{\"productCharacteristic\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}},\"required\":[\"name\"]}},\"productSpecification\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"}},\"required\":[\"id\"],\"reference\":[{\"referenceKey\":\"id\",\"table\":\"sn_prd_pm_product_specification\",\"field\":[\"sys_id\",\"external_id\"],\"errorMsg\":\"Invalid payload: Product specification does not exist\"}]}},\"required\":[\"productSpecification\"]},\"productOffering\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"}},\"required\":[\"id\"],\"reference\":[{\"referenceKey\":\"id\",\"table\":\"sn_prd_pm_product_offering\",\"field\":[\"sys_id\",\"external_id\"],\"errorMsg\":\"Invalid payload: Product offering does not exist\"}]},\"productOrderItemRelationship\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\"},\"relationshipType\":{\"type\":\"string\"}},\"required\":[\"id\",\"relationshipType\"]}}},\"required\":[\"id\",\"action\",\"product\",\"productOffering\"]}}},\"required\":[\"productOrderItem\",\"relatedParty\"]}",
Once we modify the Constants Include, we now need to modify “productorderprocessor” script include so that product order is processed and new schema is called.
Now you can generate the JSON for your Service Order and consume it via Open API under REST Explorer. Sample JSON is as below.
Note: - You need to handle the situations where the customer account is being referenced in Flows, sub Flows or at any other places so that the decomposition is not affected.
Hope this helps.
Please bookmark the article, mark it as helpful and share it with others for future refrences.
Thank You!Regards,
Kailash
https://www.servicenow.com/community/telecom-articles/consumer-support-in-tsm-product-order-and-service-order/ta-p/2324304
