D365 POS extensions - Add extension properties to cart

Within Dynamics 365 for commerce there are often a need to add extension properties to existing objects. Adding extension properties to the cart object is often highly used.

To add an extension property to the cart object in POS we can use the existing SaveExtensionPropertiesOnCartClientRequest/SaveExtensionPropertiesOnCartClientResponse pairs in POS to be able to update the cart.


The following lines of codes can be used to add a simple boolean extension property to the cart object.

var commerceProp = new ProxyEntities.CommercePropertyClass();

commerceProp.Key = "SampleExtProp";

var commercePropValue = new ProxyEntities.CommercePropertyValueClass();

commercePropValue.BooleanValue = true;

commerceProp.Value = commercePropValue;


let extensionProperties: ProxyEntities.CommercePropertyClass[] = [];

extensionProperties.push(commerceProp);


this.context.runtime.executeAsync(new SaveExtensionPropertiesOnCartClientRequest<SaveExtensionPropertiesOnCartClientResponse>(extensionProperties, this.context.logger.getNewCorrelationId())).then((response: ClientEntities.ICancelableDataResult<SaveExtensionPropertiesOnCartClientResponse>) => {

// do something

});

You can read this Microsoft doc for more details.

https://docs.microsoft.com/en-us/dynamics365/commerce/dev-itpro/commerce-runtime-extensibility#extension-properties

Comments

Popular posts from this blog

D365FO - Create a multi-select lookup in batch jobs

Generate and download a csv file using X++

Creating a batch job with query based filter in D365 back-office