A little bit of background:
We wanted to have a possibility to create quotes directly from the dashboard. In our case, it was Customer Insight Product Portfolio Dashboard where users can see Product Health and Performance. The idea is to select multiple products (for example 5 underperforming) in the matrix table and hit create a quote button.
The problem is that we don’t have currently groovy API to create a quote. However, we can still use a REST API and boudcall “hack” to do so.
The request format might not be straight forward and thus I put it here.
How it works:
The logic creates a request that adds customer, validities and some product to the quote. The quote is calculated but not saved yet.
Another request takes previous results and saves the quote.
Voila - the quote is visible in pfx and can be modified further.
See the code snippet below:
def createQuote(String quoteName, String customerId, List<String> skus) { def saveUrl = "quotemanager.save" def addProductsUrl = "quotemanager.addproducts" def expiryDate = getValidToDateString() def targetDate = getValidFromDateString() def addProductRequest = """ { "data":{ "quote": { "inputs":[ { "name": "Customer", "label": "Customer", "type": "CUSTOMER", "value": "$customerId", "valueHint": "${api.customer("Customer Name", customerId)}" } ], "outputs":[], "lineItems":[], "quoteType":"Quote", "userGroupEdit":null, "userGroupViewDetails":null, "expiryDate":"$expiryDate", "targetDate":"$targetDate", "externalRef":null, "version":null, "typedId":null, "uniqueName":null, "label":"$quoteName", "viewState":{} }, "parent": null, "skus": ${api.jsonEncode(skus)} } } """ //add items def addProductResponse = api.boundCall("localhost", addProductsUrl, addProductRequest, false) def addProductResponseStatusCode = addProductResponse.statusCode if (addProductResponseStatusCode != "200") { api.trace("error", null, addProductResponseStatusCode) return } def quoteData = addProductResponse?.responseBody?.response?.data?.getAt(0) if (!quoteData) return def saveQuoteRequest = """ { "data":{ "quote":${api.jsonEncode(quoteData)} } } """ // save quote def saveResponse = api.boundCall("localhost", saveUrl, saveQuoteRequest, false) def saveResponseStatusCode = saveResponse.statusCode if (saveResponseStatusCode != "200") { api.trace("error", null, saveResponseStatusCode) return } return "OK" } String getValidFromDateString() { Calendar calendar = api.calendar() calendar.getTime().format("yyyy-MM-dd") } String getValidToDateString() { Calendar calendar = api.calendar() calendar.add(Calendar.YEAR, 1) calendar.getTime().format("yyyy-MM-dd") }
Comments:
The quote is calculated twice as addProduct and save request calculate the whole quote.
Make sure you have bouncall partition set and ready
If you find a better way how to save the quote, please let me know.
The logic will work from whatever context, ie simple logic, PL, LPG.. only our case was the dashboard.