Create your own product mapping with Oneflow (Developers only)

Christoffer Utterborn
Christoffer Utterborn
  • Updated

Advanced Product Mapping Customization

You can replace the implementation of how we take products and discounts from Dynamics and pass them to Oneflow.

NOTE

This article is an advanced tutorial for experienced Dynamics CRM Developers.

Register plugin

  1. To replace the implementation, you’ll need to register a plugin step for the of_GetProductsPayload message:

NOTE

It should be synchronous and should execute on PostOperation.

  1. When the Execute method of your plugin is called, you’ll get the following input and output parameters:
Param name Direction Data type Description
requestData Input string JSON string contains the agreementId in Oneflow and opportunityId of the opportunity in Dynamics to take the products from.
isError Output bool Indicates whether an error occurred during the out-of-the-box operation.
errorMessage Output string Error details if an exception occurred.
result Output string Resulting JSON string of products to add to the Oneflow contract.

Examples

RequestData format

{
  "requestData": "{\"opportunityId\":\"E01D4725-8E1D-EA11-A811-000D3AB409EA\",\"contractId\":1107536}"
}

Result format

[
  {
    "products": [
      {
        "description": "description of the greatest product",
        "name": "Greatest Product ever",
        "price_1": {
          "base_amount": "15,00"
        },
        "quantity": {
          "amount": 2,
          "type": "multiple"
        }
      },
      {
        "description": "Discount for Greatest Product ever",
        "name": "Discount",
        "price_1": {
          "base_amount": "0.00",
          "discount_amount": "5,00"
        },
        "quantity": {
          "amount": 1,
          "type": "multiple"
        }
      }
    ]
  }
]

The products array contains the structure passed to the Oneflow API.

You can read more about the object structure in the Oneflow API docs at https://developer.oneflow.com/docs/product-group.

Replace JSON result

Now, if you want to have your own implementation of products, you’ll need to replace the original result JSON with your own as follows:

using Microsoft.Xrm.Sdk;
using Newtonsoft.Json;

public void Execute(IServiceProvider serviceProvider)
{
    // Obtain the execution context from the service provider
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    // Access Input parameters
    string requestData = (string)context.InputParameters["requestData"];

    // Access Output parameters (existing result)
    string result = (string)context.OutputParameters["result"];
    bool isError = (bool)context.OutputParameters["isError"];

    // Parse old result using a library like Newtonsoft.Json
    // var oldResultParsed = JsonConvert.DeserializeObject(result);

    // ... Process your logic here ...

    // Create your own JSON object
    // var myResult = ...;

    // Serialize your result back to a string
    // string myResultJson = JsonConvert.SerializeObject(myResult);

    // Update the Output parameter
    context.OutputParameters["result"] = myResultJson;
}

That’s it!

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request