ANS-0550 · SUITESCRIPT DEVELOPMENT
How to Set a URL Field Value in NetSuite SuiteScript 2.x
Understand the correct SuiteScript 2.x functions and URL formatting required for programmatically updating website fields on NetSuite records.
Short answer
To set a URL field value in NetSuite SuiteScript 2.x, load the record using `record.load`, set the 'url' field with `record.setValue`, ensuring the URL string is prefixed with 'http://' or 'https://', and then save the record using `record.save`.
Scenario
Users attempting to programmatically update a URL field on a NetSuite record via SuiteScript may encounter issues if the URL string is not correctly formatted or if outdated SuiteScript 1.0 functions are used. This often results in the URL field not saving as expected.
Solution
When setting a URL field value in NetSuite via SuiteScript, it is essential to prefix the website string with either 'http://' or 'https://' to ensure proper saving. The following SuiteScript 2.x example demonstrates how to load a customer record, update its 'url' field, and save the changes:
javascript
var customerRecord = record.load({
type: record.Type.CUSTOMER,
id: 250,
isDynamic: false
});
customerRecord.setValue({
fieldId: 'url',
value: 'http://www.test.com'
});
var prospectId = customerRecord.save();NetSuite documentation indicates that the 'http://' or 'https://' prefix is mandatory for fully qualified URLs. While exceptions for non-NetSuite resources are mentioned, practical examples of such exceptions may vary.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
