How to Create a Quote from a Logic

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 click a Create Quote button.

However, we do not currently have Groovy API to create a quote. But we can still use a REST API and bound call “hack” to do so.

The request format might not be straightforward, that is why we share this example.

How It Works

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

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

  3. The quote is visible in Pricefx 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") }

Notes

  • The quote is calculated twice as addProduct and the save request calculates the whole quote.

  • Make sure you have the boundcall partition set and ready.

  • The logic will work from any context, i.e. simple logic, PL, LPG.. This use case was the dashboard.