Versions Compared

Key

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

Available since version Paper Plane 11.0 (Paper Plane).

The Unity Pricefx Messaging API allows the external application front-end frontend to interact with Pricefx Pricefx Unity front-endfrontend. Via the API you can ask Unity Pricefx to create a new quote, update or fetch quote inputs, etc.

To enable the Messaging API, set up the Feature Flag feature flag feIntegration.active to value true.

To call Unity Pricefx from the external app front-endfrontend, use the window.postMessage() method from JavaScript in the browser.

Example , when Unity is embedded inside of of Pricefx embedded in an external application:

Code Block
languagejs
const iframe = document.getElementById('pfx-iframe');
const messageHandler = (event) => console.log(event.data);
window.addEventListener(messageHandler);
iframe.contentWindow.postMessage({
  "source": "pfxParentMessage",
  "type": "getUserData"
}, *);

In this case, you will attach a handler that logs the message it receives from UnityPricefx, and also will message Unity Pricefx requesting the logged in user data.

Example , when of an external application is embedded in UnityPricefx:

Code Block
languagejs
const messageHandler = (event) => console.log(event.data);
window.addEventListener(messageHandler);
window.parent.postMessage({
  "source": "pfxParentMessage",
  "type": "getUserData"
}, *);

The messages must have 2 fields: source and type. For most messages, there will be also a the payloadfield which will contain additional data for the sent message.Source

  • source refers to the origin of the message, which can be either pfxParentMessage or pfxChildMessage.

...

  • type defines which kind of message is being sent, and can be any of the following values described in the tables below.

Some kinds of messages will also return data , which will be also sent through postMessage too.

Please note that the messages Note: Messages described in the table below (except for getUserData and addClicLineItems) have the same signature as in Interceptor CLIC APIdescribed here.

The following messages are available for both cases (where Unity Pricefx is either the parent or a child page):

Message type

Payload

Description

Example

Response

getUserData

none

None

Returns the logged in user data.

Code Block
languagejson
{
  "source": "pfxParentMessage",
  "type": "getUserData"
}
Code Block
languagejson
{
  "source": "pricefx",
  "type": "GET_USER_DATA",
  "payload": {
    "locale": "en-gb",
    "email": "your@email.com",
    "loginName": "login.name",
    "roleNames": [...]
  }
}

getClicHeaderValue

  • fieldName

: the field’s
  • – The field's name which you would like to retrieve.

Gets

some

a header field’s value from the CLIC, i.e. quote displayed. This is only enabled when a detail page is open.

Code Block
languagejson
{
  "source": "pfxChildMessage",
  "type": "getClicHeaderValue",
  "payload": {
    "fieldName": "externalRef"
  }
}
Code Block
languagejson
{
  "source": "pricefx",
  "type": "HEADER_VALUE",
  "payload": {
    "fieldName": "externalRef",
    "fieldValue": "externalReference"
  }
}

updateClicHeaderValue

  • fieldName

: the field’s
  • – The field's name which you would like to update.

  • fieldValue

: the
  • – The new value of this field.

Updates

some

a header field’s value. This is only enabled when a detail page is open.

Code Block
languagejson
{
  "source": "pfxParentMessage",
  "type": "updateClicHeaderValue",
  "payload": {
    "fieldName": "externalRef",
    "fieldValue": "new externalRef"
  }
}
none

None

recalculate

none

None

Recalculates the CLIC displayed. This is only enabled when a detail page is open.

Code Block
languagejson
{
  "source": "pfxChildMessage",
  "type": "recalculate"
}
none

None

getClicLineItems

  • queryData

: can
  • – Can be either a query for more complex search or a string with the line item SKU.

Returns the line items matching the given queryData criteria. This is only enabled when a detail page is open.

Code Block
languagejson
{
  "source": "pfxParentMessage",
  "type": "getClicLineItems",
  "payload": {
    "queryData": "AK_0001"
  }
}
Code Block
languagejson
{
  "source": "pricefx",
  "type": "LINE_ITEMS",
  "payload": {
    "queryData": "AK_0001",
    "lineItems": []
  }
}

addClicLineItems

  • lineItems

: an
  • – An array of objects, each of them corresponding to one line item. It has one mandatory

“sku”
  • sku string field, and an optional object field

called “inputs”, where it’s
  • inputs where it is possible to pass line items inputs values.

Add

Adds a list of SKUs to the current CLIC displayed, with the option of filling some of its inputs. This is only enabled when a detail page is open.

Code Block
languagejson
{
  "source": "pfxParentMessage",
  "type": "addClicLineItems",
  "payload": {
    "lineItems": [
      {
        sku: "AK_0001',
        inputs: {
          Quantity: 3
        }
      }
    ]
  }
}
none

None

There are also messages which are exclusive to the case where Unity Pricefx is embedded inside in an external application, since they manipulate the window location:

Message type

Payload

Description

Example

Response

newQuote

newRebateAgreement

newContract

newCompensationPlan

  • targetPageState

: the
  • – The state of the newly created CLIC.

Please check

  • Check Context Linking, since this field follows the exact same signature as

it’s
  • used in Context Linking.

Creates a new quote/RBA/contract/compensation plan.

Values of this new CLIC can be passed through targetPageState

,

which reuses context linking and has the exact same API.

Code Block
languagejson
{
  "source": "pfxParentMessage",
  "type": "newQuote",
  "payload": {
    "targetPageState": {
      "targetPageFields": {
        "externalRef": "created by message"
      }
    }
  }
}
none

None

navigate

  • targetPage

  • id

Navigates

Unity

Pricefx to the given target page.

Code Block
languagejson
{
  "source": "pfxParentMessage",
  "type": "navigate",
  "payload": {
    "targetPage": "priceShopPage",
    "id": "123"
  }
}
none

None

There are also events in Unity Pricefx that will trigger a message. When submitting or recalculating a CLIC, a message will be sent containing all CLIC data, like belowsuch as:

Code Block
languagejson
{
  "source": "pricefx",
  "type": "QUOTE_RECALCULATED",
  "payload": {
    "version": 7,
    "typedId": "2147493723.Q",
    "uniqueName": "P-2147493723",
    "label": "New Quote",
    "targetDate": "2023-05-29",
    "workflowStatus": "DRAFT",
    ...
  }
}

...