web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Answered

How to get the selected cart line on the Button Click

(0) ShareShare
ReportReport
Posted on by 396

Hi All,

I have a requirement to apply a gender based discount like line discount. I have created a button in the POS. On the select of this i am able to get the whole cart details instead of the selected cart line.

By using this below code I am able to get the whole cart details

let cartRequest: CartOperations.GetCurrentCartClientRequest<CartOperations.GetCurrentCartClientResponse> =
new CartOperations.GetCurrentCartClientRequest();

// Get cart first and then find the first available cartline which does not have any discounts applied.
return context.runtime.executeAsync(cartRequest)
.then((result: ClientEntities.ICancelableDataResult<CartOperations.GetCurrentCartClientResponse>): void => {

if (!result.canceled) {
cart = result.data.result;
}
}).then((): CancelableDiscountRequest => {

if (ObjectExtensions.isNullOrUndefined(cart)) {
return <CancelableDiscountRequest>{
canceled: true,
data: null
};
}

Can you please guide me how to get the selected line from the cart?

I have the same question (0)
  • Verified answer
    Oksana Kovaliova Profile Picture
    3,597 on at

    Hi, you can create an extension of CartView controller  - to catch selected lines, save them into global variable - and use this selection in your code. Sample is below (ExtendedSessionInformation.instance in Singleton)

    export default class CartViewController extends CartView.CartExtensionViewControllerBase {

       public _selectedCartLines: ProxyEntities.CartLine[];

       constructor(context: IExtensionCartViewControllerContext) {

           super(context);

           this.cartLineSelectedHandler = (data: CartView.CartLineSelectedData): void => {

               this._selectedCartLines = data.cartLines;

               ExtendedSessionInformation.instance.selectedCartLines = data.cartLines;

           };

           this.cartLineSelectionClearedHandler = (): void => {

               this._selectedCartLines = undefined;

               ExtendedSessionInformation.instance.selectedCartLines = [];

           };

       }

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 151 Super User 2026 Season 1

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 106 Super User 2026 Season 1

#3
Zain Mehmood Profile Picture

Zain Mehmood 89 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans