anybody know if it is possible to add/create custo...
# suitescript
r
anybody know if it is possible to add/create custom record fields via suitescript?
b
the script id of a custom record field is
customrecordcustomfield
. It does not officially support suitescript
👍 1
e
function addCustomFields(custrecordId, map) {
try { var errField = ''; //capture the field id so we know where it errored out errField = map.FieldId; var newSubTable = record.create({ type: 'customrecordcustomfield', //has to be set to dynamic record in order to be able to add lines isDynamic: true, defaultValues: null }); newSubTable.setValue({ fieldId: 'rectype', //this is the internalid of the parent custom record value: custrecordId }); newSubTable.setValue({ fieldId: 'label', value: map.FieldLabel }); newSubTable.setValue({ fieldId: 'scriptid', //strip the custrecord from the CSV row since NS will add that value: map.FieldId.replace('custrecord', '') }); newSubTable.setValue({ fieldId: 'fieldtype', value: map.FieldType }); newSubTable.setValue({ fieldId: 'showinlist', value: true }); newSubTable.setValue({ fieldId: 'help', value: map.FieldHelpText }); //check if multiselect or select if (map.FieldType.indexOf('SELECT') >= 0) { //check if Use Parent if it is use the newly created record id for the custom record //if it's not use the listid from the JSON config object retrieved from the server var listId = map.ListId == 'Use Parent' ? custrecordId : map.ListId; newSubTable.setValue({ fieldId: 'selectrecordtype', value: listId }); if (map.IsParent == 'T') { newSubTable.setValue({ fieldId: 'isparent', value: true }); } } var newSubId = newSubTable.save({enableSourcing: true}); } catch (ex) { handleError(ex, 'addCustomFields ' + errField); } }