Is it possible to create a permanent custom field ...
# ask-stanley-ai
s
Is it possible to create a permanent custom field with suitescript?
c
AI generated answer (using internal Slack threads):
Yes, it is possible to create a permanent custom field with SuiteScript. You can use the
record.create
method to create a new custom field. Here is an example of how you can do this:
Copy code
javascript
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);
    }
}
This function creates a new custom field and sets its properties according to the provided map. The
record.create
method is used to create a new custom field of type 'customrecordcustomfield'. The properties of the custom field are then set using the
setValue
method. The custom field is saved using the
save
method. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83946836
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835300148
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.832880318
Please provide your feedback on this answer.