- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 04-14-2022 01:57 AM
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\"]}",
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
- 9,175 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have a confusion with getServiceOrderSchema.
getServiceOrderSchema: function() {
return JSON.parse(sn_ind_tmt_orm.TMFNewOrderAPIConstants.SCHEMA.CREATE_CONSUMER_SERVICE_ORDER);
},
Because, even after removing it, I am able to create order for consumer/account. Also getServiceOrderSchema is not called based relatedparty value.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mythili,
Yes, you can remove it as it is not required for Order generation. but it should be added for future validations (Order decomposition)so that you do not face any issues during decomposition and consumer validations.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Kailash Bhange ,
I have a business requirement to automatically create the customer account from the incoming payload, if it doesn't already exist in the platform. Do you have any suggestions on how do this?
Best regards,
cnharris1
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You can refer to productorderprocessor SI for this customizations.
the method responsible for this customer account object is ' validateRelatedPartyObj', please override this method to validate the business logic if account exists in systems or not. If it does, use same otherwise create one and use it.
SI - ProductOrderProcessor
Method - validateRelatedPartyObj
Hope, this helps you achieve the requirement.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you @Kailash Bhange !
I was able to write some code in to automatically create the account if it doesn't already exist in the platform.
Best regards,
cnharris1