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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 302 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 183 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 120 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans