How to create a quote from a logic

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:

  1. The logic creates a request that adds customer, validities and some product to the quote. The quote is calculated but not saved yet.

  2. Another request takes previous results and saves the quote.

  3. Voila - the quote is visible in pfx and can be modified further.

See the code snippet below:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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.