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
Suggested Answer

Create a custom receipt in the Retail POS D365

(0) ShareShare
ReportReport
Posted on by 396

Hi Everyone,

Hope all are you doing well and staying safe...

Basically, I have tried to create a custom receipt on the postendtransaction trigger but I did not get the receipt details in the below line

GetReceiptServiceResponse originalReceiptsResponse =
                    request.RequestContext.Runtime.Execute<GetReceiptServiceResponse>(request, request.RequestContext, receiptService, skipRequestTriggers: false);

In the originalReceiptsReposne, the receipt count is coming as 0. 

I followed the below link and tried. 

https://docs.microsoft.com/en-us/dynamics365/commerce/dev-itpro/pos-trigger-printing

Kindly help me how can I do this...

Thanks in Advance...

I have the same question (0)
  • Suggested answer
    ahgamal Profile Picture
    on at

    Hi Pankaj,

    what is the receipt type you expect to retrieve this should be based on your request can you show us what is your request look like,

    you may need to extend GetReceiptServiceRequest in CRT to handle the logic of a new receiptType.

  • Pankaj_93 Profile Picture
    396 on at

    Hi Ahmed,

    Thank you very much for your response....

    I have fixed the above issue which I had mention.

    Basically, I had forgot to add the receipt in the receipt profiles. Because of this, I was not able to retrieve the response from the GetReceiptServiceResponse.

  • Pankaj_93 Profile Picture
    396 on at

    Hi Ahmed,

    When I am testing to print the receipts, facing issues like... By standard when we will do one transaction it would print the salereceipt which is working after that it should print the another if a custom tender is used in this transaction. For this customer tender I have written code in the PostEndTransactionTrigger to print the customreceipttype7. Here it is not printing the customreceipt after salesreceipt and getting some javascript error.

  • ahgamal Profile Picture
    on at

    Hi Pankaj

    are you able to get the receipt details in the below line

    GetReceiptServiceResponse originalReceiptsResponse =

                       request.RequestContext.Runtime.Execute<GetReceiptServiceResponse>(request, request.RequestContext, receiptService, skipRequestTriggers: false);

    and what is the error that you are getting and when exactly.

  • Pankaj_93 Profile Picture
    396 on at

    Hi Ahmed,

    Yes, I am able to get the details in the GetReceiptServiceResponse.

    Error: OLE has sent a request and is waiting for a reply.

    Exactly, I have written code in the PostEndTransactions to print additional receipts.

    By debugging I am able to get response from the CRT to PosExtension. After that it is not printing the receipt.

    As I am developing this in my dev server, for the testing purpose I am using PDF to save the receipt.

    One interesting thing is that if I am making the sales receipt as Do no print then the custom receipts is working. For multiple printing it is not working. At a time only one receipt I am able to print. Whether I want to print 3-4 receipts at a time.

    Please check my TypeScript Code:

    --------------------------------------------------------------------------

    import * as Triggers from "PosApi/Extend/Triggers/TransactionTriggers";

    import { ObjectExtensions } from "PosApi/TypeExtensions";

    import { ClientEntities, ProxyEntities } from "PosApi/Entities";

    import { PrinterPrintRequest, PrinterPrintResponse } from "PosApi/Consume/Peripherals";

    import { GetHardwareProfileClientRequest, GetHardwareProfileClientResponse } from "PosApi/Consume/Device";

    import { GetReceiptsClientRequest, GetReceiptsClientResponse } from "PosApi/Consume/SalesOrders";

    export default class PostEndTransactionTrigger extends Triggers.PostEndTransactionTrigger {

      /**

          * Executes the trigger functionality.

          * @param {Triggers.IPostSuspendTransactionTriggerOptions} options The options provided to the trigger.

      */

      public execute(options: Triggers.IPostEndTransactionTriggerOptions): Promise<void> {

          this.context.logger.logVerbose("Executing PostEndTransactionTrigger with options " + JSON.stringify(options) + ".");

          if (ObjectExtensions.isNullOrUndefined(options) || ObjectExtensions.isNullOrUndefined(options.receipts)) {

              // This will never happen, but is included to demonstrate how to return a rejected promise when validation fails.

              let error: ClientEntities.ExtensionError

                  = new ClientEntities.ExtensionError("The options provided to the PostEndTransactionTrigger were invalid.");

              return Promise.reject(error);

          } else {

              let hardwareProfileCommon: ProxyEntities.HardwareProfile = null;

              return this.context.runtime.executeAsync(new GetHardwareProfileClientRequest())

                  .then((response: ClientEntities.ICancelableDataResult<GetHardwareProfileClientResponse>)

                      : Promise<ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>> => {

                      let hardwareProfile: ProxyEntities.HardwareProfile = response.data.result;

                      hardwareProfileCommon = response.data.result;

                      // Gets the receipts.

                      let salesOrderId: string = options.receipts[0].TransactionId;

                      let receiptRetrievalCriteria: ProxyEntities.ReceiptRetrievalCriteria = {

                          IsCopy: false,

                          IsRemoteTransaction: false,

                          IsPreview: false,

                          QueryBySalesId: true,

                          ReceiptTypeValue: ProxyEntities.ReceiptType.CustomReceipt6,

                          HardwareProfileId: hardwareProfile.ProfileId

                      };

                      let getReceiptsClientRequest: GetReceiptsClientRequest<GetReceiptsClientResponse> =

                          new GetReceiptsClientRequest(salesOrderId, receiptRetrievalCriteria);

                      return this.context.runtime.executeAsync(getReceiptsClientRequest);

                  })

                  .then((response: ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>)

                      : Promise<ClientEntities.ICancelableDataResult<PrinterPrintResponse>> => {

                      let receipts: ProxyEntities.Receipt[] = response.data.result;

                      // Prints the receipts.

                      let printerPrintRequest: PrinterPrintRequest<PrinterPrintResponse> = new PrinterPrintRequest(receipts);

                      return this.context.runtime.executeAsync(printerPrintRequest);

                  })

                  .then((response: ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>)

                      : Promise<ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>> => {

                      //let hardwareProfile: ProxyEntities.HardwareProfile = response.data.result;

                      // Gets the receipts.

                      let salesOrderId: string = options.receipts[0].TransactionId;

                      let receiptRetrievalCriteriaForCircleLoyalty: ProxyEntities.ReceiptRetrievalCriteria = {

                          IsCopy: false,

                          IsRemoteTransaction: false,

                          IsPreview: false,

                          QueryBySalesId: true,

                          ReceiptTypeValue: ProxyEntities.ReceiptType.CustomReceipt7,

                          HardwareProfileId: hardwareProfileCommon.ProfileId

                      };

                      let getReceiptsClientRequestCircleLoyalty: GetReceiptsClientRequest<GetReceiptsClientResponse> =

                          new GetReceiptsClientRequest(salesOrderId, receiptRetrievalCriteriaForCircleLoyalty);

                      return this.context.runtime.executeAsync(getReceiptsClientRequestCircleLoyalty);

                  })

                  .then((response: ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>)

                      : Promise<ClientEntities.ICancelableDataResult<PrinterPrintResponse>> => {

                      let receipts: ProxyEntities.Receipt[] = response.data.result;

                      // Prints the receipts.

                      let printerPrintRequest: PrinterPrintRequest<PrinterPrintResponse> = new PrinterPrintRequest(receipts);

                      return this.context.runtime.executeAsync(printerPrintRequest);

                  })

                  .then((): Promise<void> => {

                      // Resolves to a void result when fulfilled.

                      return Promise.resolve();

                  }).catch((reason: any): Promise<void> => {

                      // Resolves to a void result when rejected. This matches existing POS printing behavior.

                      this.context.logger.logError("PostEndTransactionTrigger execute error: " + JSON.stringify(reason));

                      return Promise.resolve();

                  });

          }

      }

    }

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
Siv Sagar Profile Picture

Siv Sagar 283 Super User 2025 Season 2

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 213 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans