Setting Values to a Country List/Record Field

In Netsuite, the Standard Country list’s internal id cannot be seen through UI. We need to find the internal id of the country we are about to set to the field

Solution

Get the country value from any of the Netsuite records and store it in a variable

For ex: Pulling ship country from sales order and setting that value to a country list/record custom field of a custom record.

var shipCountry=salesorder.getValue('shipcountry) //or retreive from the address book
 var stateSearchObj = _search.create({
                        type: "state",
                        filters:
                            [
                                ["country","anyof",shipCountry]
                            ],
                        columns:
                            [

                                _search.createColumn({name: "country", label: "Country"})
                            ]
                    });
                    var res=stateSearchObj.run().getRange(0,100);
                    var country=res[0].getText("country") //get Country as text from the search
var shipCountryField=custrecord.getField({fieldId:'custrecord_vv_shipment_ship_country'}) //retreive the field
                    var shipList=shipCountry.getSelectOptions({filter:country,filteroperator:'is'}) //find the exact match from search with the country list of netsuite
//This will return a array of value and a text field ex: {value:"230",text:"United States"}

custrecord.setValue({fieldId: custrecord_vv_shipment_ship_country, value: shipList[0].value}) //set value to the field with that internal id of the country

Leave a comment

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