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.