Warning banner on the sales order record when Re-print Picking Ticket

To show a warning banner message on the sales orders record when a user opens a sales order that has a Picking Ticket generated within 24hrs, use the below-added code in the user event script ‘beforeLoad’ entry point.

beforeLoad: function (scriptContext) {
                try {

                    if (scriptContext.type == scriptContext.UserEventType.VIEW) {

                      let salesOrderId = scriptContext.newRecord.getValue({fieldId: 'id'});
                        let salesOrderSearchObj = search.create({
                            type: "salesorder",
                            filters:
                                [
                                    ["type", "anyof", "SalesOrd"],
                                    "AND",
                                    ["printedpickingticket", "is", "T"],
                                    "AND",
                                    ["mainline", "is", "T"],
                                    "AND",
                                    ["formulatext: CASE WHEN {today}-{systemnotes.date} > 1 THEN 1 ELSE 0 END", "isnot", "1"],
                                    "AND",
                                    ["systemnotes.field", "anyof", "TRANDOC.BPRINTEDPICKINGTICKET"],
                                    "AND",
                                    ["internalid", "anyof", salesOrderId]
                                ],
                            columns:
                                [
                                    search.createColumn({
                                        name: "internalid",
                                        summary: "GROUP",
                                        label: "Internal ID"
                                     }),
                                     search.createColumn({
                                        name: "date",
                                        join: "systemNotes",
                                        summary: "MAX",
                                        label: "Date"
                                     })
                                ]
                        });
                        let searchResultCount = salesOrderSearchObj.runPaged().count;
                        log.debug("salesOrderSearchObj result count", searchResultCount);

                        if (checkForParameter(searchResultCount) && searchResultCount > 0) {
                            let printTicketBanner = message.create({
                                type: message.Type.ERROR,
                                title: 'Warning: Ticket Recently Printed',
                                message: 'Picking ticket was already generated for this order within the last 24 hours.',
                                // duration: 10000
                            });
                            printTicketBanner.show();
                            scriptContext.form.addPageInitMessage(printTicketBanner);
                        }
                    }
                } catch (e) {
                    log.debug('error@beforeLoad', e);
                }
            },

Leave a comment

Your email address will not be published. Required fields are marked *