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?

  • Verified answer
    Oksana Kovaliova Profile Picture
    3,597 on at
    RE: How to get the selected cart line on the Button Click

    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,886 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,768 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans