RE: How to set field id: projecttemplate via SuiteScript 2.0


I have a client script deployed to Case records.  I’m working on adding a “Create Project” button to the Case record.  The button will create a project and log the newly created project id to the existing Case record.  When creating the project, I’m gathering information from the Case record (and associated Customer) to set on the Project.  One of the fields I’d like to set on the new is “Project Template”, a standard NetSuite field (field id: projecttemplate).  I am not able to do so, via testing the script in the UI, using the debugger, or the console.  I’ve tried both record.setValue and record.setText.  I do not think I can use record.submitFields, since a record id does not exist at that point in time and the Project Template can only be set upon project creation.  Any assistance would be greatly appreciated!

Console code to test setting the field:

require (['N/currentRecord'],
var curRec = currentRecord.get();
console.log('curRec: ', curRec);
fieldId: 'projecttemplate',
value: 128
var projecttemplate = curRec.getValue({
fieldId: 'projecttemplate'
console.log('projecttemplate: ', projecttemplate);


Entire Client Script function to create project code:

function createProject(){
//get data from Case/Client to send to New Project record
var caseRecord = currentRecord.get();
var customer = caseRecord.getValue({
fieldId: 'company'
if (!customer){
alert('Cannot create a project since "Client" is not selected.');
var caseType = caseRecord.getValue({
fieldId: 'custevent_ee_case_issue_type'
//format new Project name.  Should be Customer Name Market Abbreviation "Service Work Order" Date
var name = caseRecord.getText({
fieldId: 'company'
var market = caseRecord.getValue({
fieldId: 'custevent_ee_case_market'
//get date and format for title
d = new Date();
mon = d.getMonth() +1;
day = d.getDate();
year = d.getFullYear().toString().slice(-2);
var today = mon +'/'+ day +'/'+ year;
var projectName = name+' '+market+' Service Work Order '+today
//switch to define which template to use
var template ;
var options = {
title: 'Project Template Unknown',
message: 'Select the Correct Project Template.',
buttons: [
{label: 'Upgrade', value: 127122 },
{label: 'RMA', value: 127120 },
{label: 'Sub-Contractor', value: 127124 },
{label: 'Cancel', value: 'Cancel'}
var userInput = dialog.create(options);
if (userInput == 'Cancel'){
alert('Project not created, due to user not selecting a Project Template when prompted.');
template = userInput;
//create new project
var newProject = record.create({
type: record.Type.JOB,
isDynamic: true,  //default is false
fieldId: 'custentity38',  //Project Type
value: 2
fieldId: 'customform',
value: 128
fieldId: 'companyname',
value: projectName
fieldId: 'parent',
value: customer
fieldId: 'projecttemplate',
value: template
var newProjectId ={
enableSourcing: true, //default is false
ignoreMandatoryFields: true  //default is false
//set Project field on case record with the new project id
type: record.Type.SUPPORT_CASE,
values: {
custevent_ee_case_associated_project: newProjectId
options: {
//enableSourcing: false,  ///default is true
ignoreMandatoryFields : true //default is false
alert('Done creating Project.');
//refresh current page'', '_self');
//display newly created project in a new tab''+newProjectId, '_blank');


MarthaJ Rookie Asked on December 16, 2020 in SuiteScript.
Add Comment
1 Answers

dialog.create is asynchronous, it returns a Promise that eventually returns a value that you can use. Your code is creating the project before the Promise is fulfilled. Take a look at the N/ui/dialog Module examples and look into how Promises work.

Intermediate Answered on December 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.