Render the view without reload

We have tried to update the quantity on the page similar to the purchase history detail page and the value is updated on the sales order using the suite let. We have to show the changes on the sales order without reloading the page.

the code to render the view again is added below:

    updateQuantityForMobile: function updateQuantityForMobile(val,e) {
            try {
                var self = this;
                console.log("selfsruhty", self);
                var profile = ProfileModel.ProfileModel ? ProfileModel.ProfileModel.getInstance() : ProfileModel.getInstance();
                var customFields = profile.attributes.customfields;
                var checkApprover = _.findWhere(customFields, {
                    name: "custentity_jj_approver"
                })
                console.log("profileeeeeeeee", checkApprover.value);
                var $forms = $(e.target).closest('[data-type="order-item"]');
                var $alert_placeholder_out = $forms.find('[data-type=alert-placeholder-quantity]');
                var messageOut;
                if (self.model.attributes.options.custbody_jj_approval_status === '1' && checkApprover.value) {
                    // Get the QUANTITY value
                    console.log("valueQuantity", val);
                    // Get the transactionID
                    var transid = self.id;
                    console.log("eee transid", transid);
                    // Get the SKU value
                    var sku = e.target.getAttribute('sku');
                    // Use the SKU value as needed
                    console.log('SKU:', sku);
                    var object = {
                        Action: 'Update',
                        SO_Id: transid,
                        quantity: val,
                        itemid: sku
                    }
                    this.ApprovalModel.save(object, {
                        type: 'POST'
                    }).fail(function (e) {
                        var error = e.responseJSON;
                        self.showError(error.errorMessage);

                    }).done(function (data) {
                        console.log("Post data", data);
                        var $form = $(e.target).closest('[data-type="order-item"]');
                        var $alert_placeholder = $form.find('[data-type=alert-placeholder-quantity]');
                        var message;
                        var success = data.successMessage;
                        var reason = data.reason;
                        // Check the value of the success
                        if (success == "false") {
                            message = Utils.translate('Sorry! The Quantity is not updated<br/>' + reason);
                            var alert = new GlobalViewsMessageView({
                                message: message,
                                type: 'warning',
                                closable: true
                            });
                            alert.show($alert_placeholder, 6000);
                        } else {
                            console.log('updated successfully');
                            message = Utils.translate('The Quantity updated successfully');
                            var alert = new GlobalViewsMessageView({
                                message: message,
                                type: 'success',
                                closable: true
                            });
                            alert.show($alert_placeholder, 6000);
                            self.ApprovalModel.fetch({
                                data: {
                                    internalid: self.id,
                                    recordtype: self.recordtype,
                                },
                            }).done(function (data) {
                                console.log('Successww tharay',data);
                                self.render();
                            })   
                            // Reload the page
                            //window.location.reload();
                        }

  getContext: function getContext() {
            //@class JJ.OrderApprovalDetail.OrderApprovalDetail.View.Context
            var self = this;
            var transaction_record_origin_instore = _.findWhere(
                Configuration.get('transactionRecordOriginMapping'),
                { id: 'inStore' }
            );
            //Check Approver permission and SO Status
            var profile = ProfileModel.ProfileModel ? ProfileModel.ProfileModel.getInstance() : ProfileModel.getInstance();
            _.each(profile.attributes.customfields, function (eachResult) {
                if (eachResult.name === 'custentity_jj_approver' || eachResult.name === 'T') {
                    self.approverCheck = true;
                } else {
                    self.approverCheck = false;
                }
            });
            //Check Approver permission Ends.
            var transaction_record_origin = _.findWhere(
                Configuration.get('transactionRecordOriginMapping'),
                { origin: this.model.get('origin') }
            );
            this.isInStore = this.model.get('origin') === transaction_record_origin_instore.origin;
            this.accordionLimit = Configuration.accordionCollapseLimit;
            this.non_shippable_lines = this.getNonShippableLines();
            this.in_store_lines = this.getInStoreLines();
            var return_authorizations = this.getReturnAuthorizations();
            var order_ship_method = this.model.get('shipmethod');
            var delivery_method_name = '';
            var status = this.model.get('status');
            var created_from = this.model.get('createdfrom');
            var createdFromName = '';
            var createFromUrl = '';
            if (created_from) {
                createdFromName =
                    created_from.name &&
                    created_from.recordtype === 'SalesOrd' &&
                    Utils.translate('Purchase Number: $(0)', created_from.name);
                if (created_from.internalid) {
                    createFromUrl =
                        created_from.recordtype === 'SalesOrd'
                            ? `purchases/view/salesorder/${created_from.internalid}`
                            : `quotes/${created_from.internalid}`;
                }
            }
            if (order_ship_method && this.model.get('shipmethods')._byId[order_ship_method]) {
                delivery_method_name = this.model
                    .get('shipmethods')
                    ._byId[order_ship_method].getFormattedShipmethod();
            } else if (order_ship_method && order_ship_method.name) {
                delivery_method_name = order_ship_method.name;
            }
            var { sca } = this.application.getConfig();
            var newStatus = self.ApprovalModel.get("status");
            if (newStatus.name) {
                self.model.set("status", newStatus);
            }

                var newLine = self.ApprovalModel.attributes.lines;
                self.model.set("lines",newLine);
                var newSummary = self.ApprovalModel.attributes.summary;
                self.model.set("summary",newSummary);
            }
            // Setting Approval button
            if (self.model.attributes.status && newStatus.name !== "Pending Approval") {
                self.showApprove = false;
            } else {
                self.showApprove = true;
            }
            if (self.model.attributes.status && newStatus.name === "Rejected") {
                self.showReject = true;
                self.showReason = self.ApprovalModel.attributes.rejection_reason;
            }
            return {
                // @property {OrderHistory.Model} model
                model: this.model,
                // @property {Boolean} showNonShippableItems
                showNonShippableLines: !!this.non_shippable_lines.length,
                // @property {Boolean} showNonShippableLinesAccordion
                showNonShippableLinesAccordion: this.non_shippable_lines.length > this.accordionLimit,
                // @property {Array} nonShippableItems
                nonShippableLines: this.non_shippable_lines,
                // @property {Boolean} nonShippableItemsLengthGreaterThan1
                nonShippableLinesLengthGreaterThan1: this.non_shippable_lines.length > 1,
                // @property {Boolean} showNonShippableItems
                showInStoreLines: !!this.in_store_lines.length,
                // @property {Boolean} showInStoreLinesAccordion
                showInStoreLinesAccordion: this.in_store_lines.length > this.accordionLimit,
                // @property {Array} nonShippableItems
                inStoreItems: this.in_store_lines,
                // @property {Boolean} nonShippableItemsLengthGreaterThan1
                inStoreLinesLengthGreaterThan1: this.in_store_lines.length > 1,
                // @property {Transaction.Line.Collection} lines
                lines: this.model.get('lines'),
                // @property {Boolean} collapseElements
                collapseElements: sca.collapseElements,
                // @property {Address.Model} billAddress
                showBillAddress: !!this.billaddress,
                // @property {Boolean} showOrderShipAddress
                showOrderShipAddress: !!this.model.get('shipaddress'),
                // @property {Address.Model} orderShipaddress
                orderShipaddress: this.model.get('shipaddress')
                    ? this.model.get('addresses').get(this.model.get('shipaddress'))
                    : null,
                // @property {Boolean} showReturnAuthorizations
                showReturnAuthorizations: !!return_authorizations.length,
                // @property {Object} returnAuthorizations
                returnAuthorizations: return_authorizations,
                // @property {String} deliveryMethodName
                deliveryMethodName: delivery_method_name || '',
                // @property {Boolean} showDeliveryMethod
                showDeliveryMethod: !!delivery_method_name,
                // @property {Boolean} isInStore
                isInStore: this.isInStore,
                // @property {Boolean} showPaymentMethod
                showPaymentMethod: !this.getPayments().length,
                // @property {Boolean} initiallyCollapsed
                initiallyCollapsed: Utils.isPhoneDevice() ? '' : 'in',
                // @property {Boolean} initiallyCollapsedArrow
                initiallyCollapsedArrow: Utils.isPhoneDevice() ? 'collapsed' : '',
                // @property {String} originName
                originName: transaction_record_origin.name,
                // @property {String} title
                title: transaction_record_origin.detailedName,
                // @property {Boolean} showPaymentEventFail
                showPaymentEventFail:
                    this.model.get('paymentevent').holdreason === 'FORWARD_REQUESTED' &&
                    status.internalid !== 'cancelled' &&
                    status.internalid !== 'closed',
                // @property {Boolean} showEstimateDetail
                showQuoteDetail: !!created_from && created_from.name,
                // @property {String} quoteName
                quoteName: createdFromName || Utils.translate('Quote #$(0)', created_from.name),
                // @property {String} estimateURL
                quoteURL: createFromUrl,
                // @property {Boolean} showPurchaseOrderNumber
                showPurchaseOrderNumber: !!this.model.get('purchasenumber'),
                approverCheck: this.approverCheck,
                showApprove: this.showApprove,
                showReject: this.showReject,
                showReason: this.showReason || "Reason not provided"
            };
        }

Leave a comment

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