Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / Create a custom receip...
Commerce forum
Suggested answer

Create a custom receipt in the Retail POS D365

Posted on by 392

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...

Categories:
  • Pankaj_93 Profile Picture
    Pankaj_93 392 on at
    RE: Create a custom receipt in the Retail POS D365

    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();

                  });

          }

      }

    }

  • ahgamal Profile Picture
    ahgamal on at
    RE: Create a custom receipt in the Retail POS D365

    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
    Pankaj_93 392 on at
    RE: Create a custom receipt in the Retail POS D365

    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.

  • Pankaj_93 Profile Picture
    Pankaj_93 392 on at
    RE: Create a custom receipt in the Retail POS D365

    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.

  • Suggested answer
    ahgamal Profile Picture
    ahgamal on at
    RE: Create a custom receipt in the Retail POS D365

    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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans