1

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.

Gus Larson
  • 13
  • 2

1 Answers1

0

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

});
desertnaut
  • 57,590
  • 26
  • 140
  • 166
SCA Dev
  • 16
  • 3
  • 1
    Please don't post code as images. Code should be pasted as text, and formatted using Markdown. (The toolbar in the Stack Overflow editor can help you with this.) Code within images is harder to read, less accessible, can't be copied, and doesn't show up in relevant searches. Please [edit] your post to include the code as text; this will help you get better responses, and help prevent your answer from getting deleted. – Jeremy Caney May 24 '23 at 00:17