0
votes

We created a suitescript 2.0 script in our netsuite environment. We are using RESTlet to access it.

Our script creates a sales order with various fields. It works fine but we are unable to set a coupon code value or a partner code, we get the same error for both. We are using Internal ID and we tried coupon code itself as well.

Any idea?

Error:

{
    "type":"error.SuiteScriptError",
    "name":"INVALID_FLD_VALUE",
    "message":"You have entered an Invalid Field Value 18 for the following field: couponcode",
    "stack":[
        "<anonymous>(N/record/recordService.js)",
        "setSalesOrderData(adhoc$-1$debugger.user:71)",
        "saveSaleOrder(adhoc$-1$debugger.user:17)",
        "<anonymous>(adhoc$-1$debugger.user:107)",
        "<anonymous>(adhoc$-1$debugger.user:6)"
        ],
    "cause":{
        "type":"internal error",
        "code":"INVALID_FLD_VALUE",
        "details":"You have entered an Invalid Field Value 18 for the following field: couponcode",
        "userEvent":null,
        "stackTrace":[
            "<anonymous>(N/record/recordService.js)",
            "setSalesOrderData(adhoc$-1$debugger.user:71)",
            "saveSaleOrder(adhoc$-1$debugger.user:17)",
            "<anonymous>(adhoc$-1$debugger.user:107)",
            "<anonymous>(adhoc$-1$debugger.user:6)"
        ],
        "notifyOff":false},"id":"","notifyOff":false
    }
}

RESTlet code:

var objRecord = record.create({
    type: record.Type.SALES_ORDER,
    isDynamic: true
});

/* add other values.....*/

objRecord.setValue({ fieldId: 'couponcode', value: 538 });

var recordId = objRecord.save({
    enableSourcing: false,
    ignoreMandatoryFields: false
});
2

2 Answers

1
votes

Are these coupon codes you are trying to set One-Time Use codes? Or are they linked to a Promotion?

Which internal ID are you using in the couponcode field?

Can you share the relevant parts of your RESTlet code as well?

I tested the following in the console (i.e. a Client Script) on a Sales Order, and it seems to set a Promotion and Coupon Code appropriately:

require(["N/currentRecord"], function(c) { 
    c.get().setValue({
        "fieldId": "couponcode",
        "value": 1
    });
});

where 1 is the internal ID of the Promotion. If I use an internal ID not associated to a Promotion, I get no error, but nothing is populated in either field.

0
votes

we finally got working code from Netsuite support, since there is such little help on this topic online, I am sharing it here. We grabbed what we needed into our own script, but this basic one works as well,

From netsuite support agent:

I created a simple SuiteScript 2.0 code for entering the values into Partner field (id: 'partner') and Coupon Code (id: 'couponcode'). Both fields are dropdown fields not multiselect fields. The field Coupon Code depends on Promotion field that's why we should enter value in 'promocode' field instead of 'couponcode'.

/**
 *@NApiVersion 2.x
 *@NScriptType usereventscript
 */

define(['N/record'],
    function(record) {

        function AfterSubmit(context) {


            var result = record.load({
                type: 'salesorder',
                id: 71040,
                isDynamic: true
            });

            result.setValue ({
                fieldId : 'partner',
                value : 45140
            });
            result.setValue ({
                fieldId : 'couponcode',
                value : 'AMARILLO16'
            }); 
            result.save({
                enableSourcing : false,
                ignoreMandatoryFields : true
            });
            return true;
        }

        return {
            afterSubmit: AfterSubmit
        };
});

We had to do one modification for it to work for us:

 result.setValue ({
            fieldId : 'partner',
            value : 45140
        });
        result.setText ({
            fieldId : 'couponcode',
            text : 'AMARILLO16'
        }); 
        result.save({
            enableSourcing : false,
            ignoreMandatoryFields : true
        });