Developer forum

Forum » Integration » Extensions to Code Unit for BC Cloud

Extensions to Code Unit for BC Cloud

Chris Søgaard
Chris Søgaard
Reply

Hi

We have a customer with a D365 BC Cloud sokution, and we're trying to extend the Code Unit, specifically on the products feed, to have it return additional tables. In connection with this I have received the following question from the customer's BC developer, which I hope someone can help with:


Is it possible to get an example of how to extend the products feed to have it return additional tables. We're currently using this request:

<GetEcomData><tables><Products type="all" setLanguage="ENU" languages="DAN, DEU, FRA" importProductProperties="true" /></tables></GetEcomData>

When looking at the documentation the closest example on this is the <GetCompanies></GetCompanies> found here:

https://doc.dynamicweb.com/documentation-9/integration/integration-framework-2/extensibility/extending-the-microsoft-dynamics-365-business-central-plugin-unit#9333

but this is an entirely new request, we only want to extend the existing request with additional tables. Is that possible?

 

Additionally it is recommended to use the variable var responseDoc: XmlDocument to build the response, but when subscribing to the event OnBeforeGetProductsRequest you can only use var responseRootNode: XmlNode.


I hope someone can help with al examples on this feature

 

BR Chris


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Chris,
yes, you need to use the OnAddProductXmlNode subscriber and add your custom logic there.
There is an example code available in the Example projects that are available on the doc site for the different BC versions (links names end with Example Extension):

/// <summary>
    /// Add custom field to the products xml
    /// </summary>
    [EventSubscriber(ObjectType::CodeunitCodeunit::DynamicwebProductsPublisher, 'OnAddProductXmlNode''', true, true)]
    procedure OnAddProductXmlNode(var productNode: XmlNode; item: Record Item);
    begin
        //Adds custom field ProductProfitPercent to the product xml node:
        //<column columnName="ProductProfitPercent"><![CDATA[99]]></column>
        XmlHelper.AddField(productNode, 'ProductProfitPercent', Format(item."Profit %"));
    end;


Kind regards, Dmitrij

 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitriy

Thank you for the quick response.

But as I see it this will only give us the oppotunity to add fields/columns to the product XML node and not adding new tables to the general feed for getting products. Maybe it was not clear on my examples but want we want to achieve is to call with the request above, and then receive all tables as usual (EcomProducts, EcomProductCategory etc.) but then also e.g. "EcomUnitsOfMeasure table, which is not part of the standard response but an entirely new table added to rhe response.

/Chris

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Chris,
then you need to use the OnAfterGetProductsRequest event and the sample code is got from the zipped archives with the Example projects sources:

[EventSubscriber(ObjectType::CodeunitCodeunit::DynamicwebProductsPublisher, 'OnAfterGetProductsRequest''', true, true)]
    procedure OnAfterGetProductsRequest(var requestDoc: XmlDocumentvar responseRootNode: XmlNode);
    begin
        XmlHelper.AddCustomElement('OnAfterGetProductsRequest', responseRootNode);
    end;

This code will output the xml like this:
<?xml version="1.0" encoding="utf-16"?>
<tables version="1.2.0.12_NAV18.0.22893.23390">
  <table tableName="EcomProducts">
    <item table="EcomProducts">
      <column columnName="ProductId"><![CDATA[1900-S]]></column>
      <column columnName="ProductVariantId"><![CDATA[]]></column>
      <column columnName="ProductIdentifier"><![CDATA[1900-S..LANG1]]></column>
      <column columnName="ProductNumber"><![CDATA[1900-S]]></column>
      <column columnName="ProductName"><![CDATA[PARIS Guest Chair, black]]></column>
      <column columnName="ProductPrice"><![CDATA[1,071.062]]></column>
      <column columnName="ProductStock"><![CDATA[299]]></column>
      <column columnName="ProductCurrencyCode"><![CDATA[DKK]]></column>
    </item>
  </table>
  <OnAfterGetProductsRequest>extendable</OnAfterGetProductsRequest>
</tables>
So you can extend the sample code to return any other tables you want.
Kind regards, Dmitrij

Votes for this answer: 1
 
Chris Søgaard
Chris Søgaard
Reply

Yes I see, this seems to provide what we want.

Thank you

 

You must be logged in to post in the forum