Developer forum

Forum » Integration » Customize EcomProductCategoryFieldValue integration from Business Central

Customize EcomProductCategoryFieldValue integration from Business Central

John Cristian Villamar Cueva
Reply

Hello everybody, I need help with the following, I have to customize the variant field in the integration of the EcomProductCategoryFieldValue table, look in AllExtensibilityEvents.svg, but I could not find any event where I can configure the nodes for this segment of the xml.
I am using this request:
<GetEcomData><tables><Products type="all" setLanguage="ESM" languages="ESM,ENU" importProductProperties="true"/></tables></GetEcomData>

I retrieve this item table, which is where I need to customize one of the fields:
  <table tableName="EcomProductCategoryFieldValue">
     <item table="EcomProductCategoryFieldValue">
       <column columnName="FieldValueFieldId"><![CDATA[ImportedNAVItemAttributes_1]]></column>
       <column columnName="FieldValueFieldCategoryId"><![CDATA[ImportedNAVItemAttributes]]></column>
       <column columnName="FieldValueProductId"><![CDATA[ACE40003/X]]></column>
       <column columnName="FieldValueProductVariantId"><![CDATA[]]></column>
       <column columnName="FieldValueProductLanguageId"><![CDATA[ESM]]></column>
       <column columnName="FieldValueValue"><![CDATA[35]]></column>
     </item>
  I would greatly appreciate anyone who can give me a hand on this issue.

BR. John Villamar.

 


Replies

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

Hi John,
unfortunatelly there is no event for that specific table, but you can try to use the OnAfterGetProductsRequest event that is fired after the request was processed and its response xml is generated so it contains the generated output xml. Then you could query the xml content and replace the values in it where needed. There is a xml helper codeunit with some xml methods that can help to update the xml:
Codeunit DynamicwebXmlHelper;
methods: AddOrUpdateFieldValue and GetTextFromNode
BR, Dmitrij
 

Votes for this answer: 1
 
John Cristian Villamar Cueva
Reply

Hi Dmitriy, I followed your suggestion and added the following code in the event that you recommended.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::DynamicwebProductsPublisher, 'OnAfterGetProductsRequest', '', true, true)]
    procedure OnAfterGetProductsRequest(var requestDoc: XmlDocument; var responseRootNode: XmlNode);
    var
        xmlNodes: XmlNodeList;
        DWXmlHelper: Codeunit DynamicwebXmlHelper;

    begin
        XmlHelper.AddCustomElement('OnAfterGetProductsRequest', responseRootNode);
        responseRootNode.SelectNodes('//item', xmlNodes);
        xmlNodes.Get(xmlNodes.Count, responseRootNode);
        DwXmlHelper.AddOrUpdateFieldValue(responseRootNode, 'FieldValueProductId', ConvertStr(DWXmlHelper.GetTextFromNode(responseRootNode, 'column[@columnName=''FieldValueProductId'']'), '/', '_'));
    end;

But the result is that it only updates the last Item, the letters are in red.

   </item>
    <item table="EcomProductCategoryFieldValue">
      <column columnName="FieldValueFieldId"><![CDATA[ImportedNAVItemAttributes_9]]></column>
      <column columnName="FieldValueFieldCategoryId"><![CDATA[ImportedNAVItemAttributes]]></column>

      <column columnName="FieldValueProductId"><![CDATA[PEZ21269/X]]></column>
      <column columnName="FieldValueProductVariantId"><![CDATA[]]></column>
      <column columnName="FieldValueProductLanguageId"><![CDATA[ESM]]></column>
      <column columnName="FieldValueValue"><![CDATA[67]]></column>
    </item>
    <item table="EcomProductCategoryFieldValue">
      <column columnName="FieldValueFieldId"><![CDATA[ImportedNAVItemAttributes_9]]></column>
      <column columnName="FieldValueFieldCategoryId"><![CDATA[ImportedNAVItemAttributes]]></column>

      <column columnName="FieldValueProductId"><![CDATA[PEZ21271_X]]></column>
      <column columnName="FieldValueProductVariantId"><![CDATA[]]></column>
      <column columnName="FieldValueProductLanguageId"><![CDATA[ESM]]></column>
      <column columnName="FieldValueValue"><![CDATA[63]]></column>
    </item>
  </table>

What do you think I need to add to the code so that it processes all the xml. Thank you in advance.

BR. John Villamar.

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

Hi John,
yes, thats because you missed the loop over the xml nodes, so you need to have the code like that:
 begin
        XmlHelper.AddCustomElement('OnAfterGetProductsRequest', responseRootNode);
        responseRootNode.SelectNodes('//item', xmlNodes);

//XMLNode: XmlNode;
        foreach XMLNode in xmlNodes do begin
            DwXmlHelper.AddOrUpdateFieldValue(XMLNode, 'FieldValueProductId', ConvertStr(DWXmlHelper.GetTextFromNode(XMLNode, 'column[@columnName=''FieldValueProductId'']'), '/', '_'));
        end;

  end; 

BR, Dmitrij

Votes for this answer: 1
 
John Cristian Villamar Cueva
Reply

Thanks Dmitrij, everithing worked fine.

 

You must be logged in to post in the forum