0
votes

So I'm currently trying to update the title field on a NetSuite Quote record from an input on the front-end so a user can add the title themselves.

When submitting the quote I can set the title and see that it has updated the backbone model, however when the page loads the model has set the title back to null.

The functionality already exists with the memo area, and I have copied all the functions to replicated this for the title, however the memo continues to be updated, but the title does not.

I'm fairly new to the SuiteScripting and try to avoid it as much as I can, but I think the field isn't being updated and therefore not available in the model on other pages.

enter   ,   update: function (record_type, id, data_model)
    {
        if (record_type && id)
        {
            this.recordId = id;
            this.data = data_model;

            this.record = this.getTransactionRecord(record_type, id);
            //@property {Transaction.Model.Get.Result} currentRecord This property is used so when performing any update
            //operation you can know what is the current state
            //This property is only present when performing an update operation
            this.currentRecord = this.get(record_type, id);
            this.setPaymentMethod();
            this.setLines();
            this.setAddress('ship', this.data.shipaddress, 'billaddress');
            this.setAddress('bill', this.data.billaddress, 'shipaddress');
            this.setMemo();
            // Set's our Quote title
            this.setTitle();
            // Set's our PO Number and SLC Number
            this.setCustomFields();
        }
    }

    /**
     * Adds fields to the Sales Order when generated via Quotes (possibly via other methods as well)
     */

,   setCustomFields: function ()
    {
        if (this.data.custbody_slc_number) {
            this.record.setFieldValue('custbody_slc_number', this.data.custbody_slc_number);
        }

        if (this.data.otherrefnum) {
            this.record.setFieldValue('otherrefnum', this.data.otherrefnum);
        }
    }

    /**
     * @method setTitle Sets the title attribute into the current transaction
     * @return {Void}
     */

,   setTitle: function ()
    {
        this.record.setFieldValue('title', null);

        if (this.data.title)
        {
            this.record.setFieldValue('title', this.data.title);
        }
    }

    //@method setMemo Sets the memo attribute into the current transaction
    //This method does not use any parameters as it use this.data and this.record
    //@return {Void}
,   setMemo: function ()
    {
        this.record.setFieldValue('memo', null);

        if (this.data.memo)
        {
            this.record.setFieldValue('memo', this.data.memo);
        }
    }

This is where the setTitle() function is created and called on update.

, submit: function () {

            this.wizard.model.set('memo', this.$('[data-type="memo-input"]').val());
            this.wizard.model.set('title', this.$('[data-type="title-input"]').val());

            console.log(this.wizard.model);

            return jQuery.Deferred().resolve();

        }

And this is the submit function.

So on submit the model is being updated using the .set() function, however it is not saving this field to the record.

I've been banging my head against this for a while now and I can't see to figure out what different between the setMemo and the setTitle.

Any help would be amazing, I would love to understand how to add data to records from the front-end but it's quite a maze to work out whats going on.

Thanks!

UPDATE

I've traced the data path back from the view submit function, to the configuration, and then to the submit to the server.

I have can see that when logging the variable through these stages, the title field gets set and saved until the page reloads to the quote confirmation page where in the 'changed' section of the model the title is redefined to 'null'.

Here is the submit function that submits the model:

,   save: function ()
                        {
                            _.first(this.moduleInstances).trigger('change_label_continue', _('Processing...').translate());
                            var self = this
                            ,   submit_opreation = this.wizard.model.submit();

                            submit_opreation.always(function ()
                            {
                                _.first(self.moduleInstances).trigger('change_label_continue', _('Submit Quote Request').translate());
                            });                     

                            return submit_opreation;
                        }
                    }

I believe that it's a suitescript issue and I don't have a lot of experience with suitescript

setTitle: function ()
        {
            // this.record.setFieldValue('title', null);

            if (this.data.title)
            {
                this.record.setFieldValue('title', this.data.title);
            }
        }

This function sets the title to 'null' however when hard coding a value here or just removing the if statement the title is still set to 'null'.

As I'm new to SuiteScripting, could anyone also point out how I could log 'this.data'?

1

1 Answers

0
votes

From what I can see the submit-function maps the input-values correctly to the (local) model ("I can [...] see that it has updated the backbone model"), but it does not finally save that model to the (remote) database after clicking on the submit button ("however when the page loads the model has set the title back to null."). This would usually be done by implementing the Backbone.Model.save - method.

You could therefore try to change your submit-function to the following:

submit: function () {

   this.wizard.model.set('memo', this.$('[data-type="memo-input"]').val());
   this.wizard.model.set('title', this.$('[data-type="title-input"]').val());

   var dff = jQuery.Deferred();

   // Send model state to database
   this.wizard.model.save(null, {
      success : function(data, response) {
         console.log('success: model saved', data);
         dff.resolve(data);
      },
      error : function() {
         console.log('error: model not saved');
         dff.reject();
      }
   }

   return dff.promise();
}