Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / Custom Field isn't...
Commerce forum

Custom Field isn't reflected to SearchView and CustomerAddEdit Form

(0) ShareShare
ReportReport
Posted on by 2

I have scenario to get a field from LOGISTICSELECTRONICADDRESS (CountryRegionCode) to show in Customer Search (SearchView) and Add/Edit (CustomerAddEdit) forms. I create GetCustomerDataRequest trigger in CRT extension.  I see example from RetailSDK\Documents\SampleExtensionsInstructions\EmailPreference.    But my case, I create new view to query the new field.   It works fine in Runtime.Extensions.TestHost.

In CommerceRuntime.ext.config, I already add types.   

<add source="type" value="Contoso.Commerce.Runtime.PhoneCountryCode.CreateOrUpdateCustomerDataRequestHandler, Contoso.Commerce.Runtime.PhoneCountryCode" />
<add source="type" value="Consoto.Commerce.Runtime.PhoneCountryCode.GetCustomerTriggers, Consoto.Commerce.Runtime.PhoneCountryCode" />

I add column in CustomerSearchColumns.ts like this

import { ICustomerSearchColumn } from "PosApi/Extend/Views/SearchView";
import { ICustomColumnsContext } from "PosApi/Extend/Views/CustomListColumns";
import { ProxyEntities } from "PosApi/Entities";

export default (context: ICustomColumnsContext): ICustomerSearchColumn[] => {
     return [
     {
          title: context.resources.getString("string_2"),
          computeValue: (row: ProxyEntities.GlobalCustomer): string => { return row.AccountNumber; },
          ratio: 10,
          collapseOrder: 6,
          minWidth: 100
     }, {
          title: context.resources.getString("string_3"),
          computeValue: (row: ProxyEntities.GlobalCustomer): string => { return row.FullName; },
          ratio: 15,
          collapseOrder: 5,
          minWidth: 120
     }, {
          title: context.resources.getString("string_4"),
          computeValue: (row: ProxyEntities.GlobalCustomer): string => { return row.FullAddress; },
          ratio: 20,
          collapseOrder: 2,
          minWidth: 200
     }, {
          title: context.resources.getString("string_5"),
          computeValue: (row: ProxyEntities.GlobalCustomer): string => { return row.Email; },
          ratio: 25,
          collapseOrder: 3,
          minWidth: 200
     }, {
          title: context.resources.getString("string_101"),
          computeValue: (row: ProxyEntities.GlobalCustomer): string => {
          let desiredProperties: ProxyEntities.CommerceProperty[] = row.ExtensionProperties.filter(
          (value: ProxyEntities.CommerceProperty): boolean => {
          return value.Key === "COUNTRYREGIONCODEPHONE";
     }
     );
          return desiredProperties.length > 0 ? desiredProperties[0].Value.StringValue : "";
     },
          ratio: 15,
          collapseOrder: 1,
          minWidth: 120
     }, {
          title: context.resources.getString("string_7"),
          computeValue: (row: ProxyEntities.GlobalCustomer): string => { return row.Phone; },
          ratio: 15,
          collapseOrder: 4,
          minWidth: 120
     }
     ];
};

And create PhoneCountryCodeSection.ts for the field 

import {
    CustomerAddEditCustomControlBase,
    ICustomerAddEditCustomControlState,
    ICustomerAddEditCustomControlContext,
    CustomerAddEditCustomerUpdatedData
} from "PosApi/Extend/Views/CustomerAddEditView";
import { ObjectExtensions } from "PosApi/TypeExtensions";
import { ProxyEntities } from "PosApi/Entities";

export default class PhoneCountryCodeSection extends CustomerAddEditCustomControlBase {
    public countryCode: Observable<string>;
    public customerIsPerson: Observable<boolean>;
    private static readonly TEMPLATE_ID: string = "Microsoft_Pos_Extensibility_Sample_PhoneCountryCodeSection";

    constructor(id: string, context: ICustomerAddEditCustomControlContext) {
        super(id, context);

    this.countryCode = ko.observable("");
    this.customerIsPerson = ko.observable(false);

    this.countryCode.subscribe((newValue: string): void => {
        this._addOrUpdateExtensionProperty("COUNTRYREGIONCODEPHONE", <ProxyEntities.CommercePropertyValue>{ StringValue: newValue });
});


    this.customerUpdatedHandler = (data: CustomerAddEditCustomerUpdatedData) => {
        this.customerIsPerson(data.customer.CustomerTypeValue === ProxyEntities.CustomerType.Person);
    };
}

    public onReady(element: HTMLElement): void {
        ko.applyBindingsToNode(element, {
            template: {
                name: PhoneCountryCodeSection.TEMPLATE_ID,
                data: this
            }
        });
    }


    public init(state: ICustomerAddEditCustomControlState): void {
        if (!state.isSelectionMode) {
            this.isVisible = true;
            this.customerIsPerson(state.customer.CustomerTypeValue === ProxyEntities.CustomerType.Person);


        }


    }

    private _addOrUpdateExtensionProperty(key: string, newValue: ProxyEntities.CommercePropertyValue): void {
        let customer: ProxyEntities.Customer = this.customer;

        let extensionProperty: ProxyEntities.CommerceProperty =
            Commerce.ArrayExtensions.firstOrUndefined(customer.ExtensionProperties, (property: ProxyEntities.CommerceProperty) => {
                return property.Key === key;
            });

        if (ObjectExtensions.isNullOrUndefined(extensionProperty)) {
            let newProperty: ProxyEntities.CommerceProperty = {
                Key: key,
                Value: newValue
            };

            if (ObjectExtensions.isNullOrUndefined(customer.ExtensionProperties)) {
                customer.ExtensionProperties = [];
            }

            customer.ExtensionProperties.push(newProperty);
         } else {
             extensionProperty.Value = newValue;
         }

         this.customer = customer;
    }


}

Can anyone explain how to link CRT extension and trigger in POS extension?    If missing something, please kindly advise.   

  • Adolfome9 Profile Picture
    Adolfome9 110 on at
    RE: Custom Field isn't reflected to SearchView and CustomerAddEdit Form

    Hi AeyPKA;

    I would like to add 3 fields to Customer, But I don't know extend customer table, then I understand that I should extend CRT and POS. Do you have some materials for this? or could you share me please a sample?

    Thanks in Advance.

  • pka Profile Picture
    pka 2 on at
    RE: Custom Field isn't reflected to SearchView and CustomerAddEdit Form

    Finally, I found the solution.   

    In CRT extension, no only override GetCustomerDataRequest, but also override SearchCustomersDataRequest (for Customer Search form) and GetCustomersDataRequest (for Customer Add/Edit form)  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans