D365fo join table as csv column in view/data entity

Below is some sample code for joining a table to a view as a calculated field. Useful when you have data represented as 1:n, but you need only one record returned for the parent datasource. My need for this came when enhancing the product search feature to include external item ids (custVendExternalItem). Using a normal join on the existing view created duplicate product RecIds on the parent data source which caused the full text index rebuild to fail on index violations. Considering the below scenario:

InventTable CustVendExternalItem

Item1 = Customer1Item

= Customer2Item

We want the view to return the following:

ItemId ExternalItemIds

Item1 Customer1Item, Customer2Item

Step1: Create an extension class for the view you are editing (or place the method directly on your custom view). Here is a sample of what worked for me. Ultimately, this will pass TSQL to the compiler. The SysComputedColumn methods are used to fetch the literal strings SQL will be using when the view runs for the morphX objects.

[ExtensionOf(viewStr(MCRProductSearchView))]

final class MCRProductSearchView_Extension

{

  public static str externalItemCSV()

  {

    return strfmt('( STUFF ( (Select \',\' + Z.ExternalItemId from CustVendExternalItem Z where Z.ModuleType in (4,6) and Z.ItemID = %1 and Z.DataAreaId = %2 FOR XML PATH(\'\'), TYPE).value(\'.\', \'VARCHAR(MAX)\'), 1,1,SPACE(0) ) ) ',

      SysComputedColumn::returnField(tableStr(MCRProductSearchView), identifierStr(InventTable), fieldStr(InventTable, ItemId)),

      SysComputedColumn::returnField(tableStr(MCRProductSearchView), identifierStr(InventTable), fieldStr(InventTable, DataAreaId)));


  }


}

Step2: Add the column to your view. Create a new String computed column on your view. If you are extending an existing view, add the following to the Method property: MCRProductSearchView_Extension::externalItemCSV  . If you are adding it to your own view, just place the method name in the "View Method" property. Note the property you use is different based on if this is an extension.

Step3: Build and Sync, done.

要查看或添加评论,请登录

Michael Schiermeyer的更多文章

  • AWS authentication in X++ for Vendor Central & others

    AWS authentication in X++ for Vendor Central & others

    The authentication step to AWS is rather complicated. A client had asked me to code the authentication step and they…

  • Default batch retry to 0

    Default batch retry to 0

    Microsoft introduced batch retry in 2021. This causes many unexpected results covered in many other articles.

    2 条评论
  • Refresh certificates on onebox dev machines

    Refresh certificates on onebox dev machines

    If you follow the onebox VHD setup, you have had to use the self signed certificate for a few years now during setup:…

    3 条评论
  • Force progress bar in X++

    Force progress bar in X++

    There are several standard, best practice approaches to showing your user a wait indicator. Such as…

  • D365 SSRS Checkboxes using wingdings

    D365 SSRS Checkboxes using wingdings

    This article is more of a reminder that this is an option when developing SSRS reports in d365. In my twelve years of…

    1 条评论
  • Server certificates and production D365fo

    Server certificates and production D365fo

    Many integrations require certificates to authenticate the identify of the caller, in this case D365fo. Most…

    2 条评论
  • D365fo custom dimension defaulting in segmented entry controls

    D365fo custom dimension defaulting in segmented entry controls

    The below outlines how to code a custom dimension defaulting logic directly into the segmented entry controls such that…

社区洞察

其他会员也浏览了