Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A little bit of backgroundBackground:

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

The problem is that we don’t have currently groovy However, we do not currently have Groovy API to create a quote. However, But we can still use a REST API and boudcall bound call “hack” to do so.

The request format might not be straight forward and thus I put it herestraightforward, that is why we share this example.

How it works:

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

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

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

See the code snippet below:

Code Block
breakoutModewide
languagegroovy
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")
}

CommentsNotes:

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

  • Make sure you have bouncall the boundcall partition set and ready (smile) If you find a better way how to save the quote, please let me know.

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