SuiteCommerce Advanced 2019.2 set custom field on quote/estimate creation

112 Views Asked by At

I'm working with a SuiteCommerce Advanced 2019.2 website. I need to set a custom field when a quote is created using the Create a Quote feature. What's the best way to do this? Do I need to make a new SuiteScript model to extend the Quote.Model or is there a better way to handle it?

I tried wrapping the submit function for Quote.Model but that didn't work. I could also overwrite the whole submit function but I only need to set this one field.

1

There are 1 best solutions below

1
SCA Dev On

Yes, you should wrap the model. In this case the "preSubmitRecord" function, which is inherited from the Transaction Model, should work fine.

// @method submit Saves the current record
    // @return {Transaction.Model.Confirmation}
    submit: function() {
        if (!this.record) {
            throw SC.ERROR_IDENTIFIERS.loadBeforeSubmit;
        }

        this.preSubmitRecord(); //<-- T

        const new_record_id = nlapiSubmitRecord(this.record);
        // @class Transaction.Model.Confirmation
        const result = {
            // @property {String} internalid
            internalid: new_record_id
        };

        return this.postSubmitRecord(result);
        // @class Transaction.Model
    },

To wrap the function, you can use the "Application.on" listener. You must also require "Application" on the definition of your file.

define('YourFile', [
    'Application'
], function(
    Application
) {
    'use strict';

    Application.on('before:Quote.preSubmitRecord', function quoteBeforePreSubmitWrapper(model) {
        model.record.setFieldValue(yourCustomField, theValue);
    });

});