Saturday, February 16, 2019

nlapiCopyRecord > Project Record > Error: Illegal ID. Please enter a name

This article will show the user ways on how to solve the error: "Illegal ID. Please enter a name." when they're trying to copy the Project record and submit the copied the record via SuiteScript.

Problem: The error "Illegal ID. Please enter a name." is thrown when running the following snippet:

var project = nlapiCopyRecord('job',440);
var projID = nlapiSubmitRecord(project);

When creating a new project record from Lists > Projects > New, users would notice that the Project ID (or the 'entityid' field) is getting copied from 'Project Name' field. However, copying this record would not copy the 'Project ID' field from the existing record as NetSuite makes sure that the 'Project ID' is unique.

Solution 1: Add a setFieldValue() method for setting the 'Project Name' field to be copied to the Project ID. Snippet below:

var project = nlapiCopyRecord('job',440);
project.setFieldValue('companyname','New Project');
var projID = nlapiSubmitRecord(project);

Solution 2: Uncheck 'autoname' field and set the 'entityid' field. Snippet below:

var project = nlapiCopyRecord('job',440);
project.setFieldValue('autoname','F');
project.setFieldValue('entityid','New Project 2');
var projID = nlapiSubmitRecord(project);

Solution 3: Turn on Auto-Generated Number (Only recommended if you'd like NetSuite to auto-generate the 'Project ID' field.) To turn this on, please go to Setup > Company > Auto-Generated Numbers. Click on the checkbox beside 'Project' record and save. The following snippet will now work.

var project = nlapiCopyRecord('job',440);
var projID = nlapiSubmitRecord(project);

No comments:

Post a Comment