RE: Trying to create a record from a script.

Answered

Hi,

I am trying to have a script that does 2 distinct tasks. I’m guessing I may need to use 2 scripts and then call the 2nd script from the 1st?

What I am trying to do, is

a) Update the externalID of the record
b) Create a new custom record with some data from the original document

The first part I can do. This is my script…

/**
* @NApiVersion 2.0
* @NScriptType ClientScript
*/
define([‘N/currentRecord’, ‘N/ui/dialog’, ‘N/log’, ‘N/record’],

function(currentRecord, dialog, log) {
function saveRecord (){
var objRecord = currentRecord.get();
var costcentre = objRecord.getValue({ fieldId: ‘entityid’})
objRecord.setValue({
fieldId: ‘externalid’,
value: costcentre
});
return true;
}
return {
saveRecord: saveRecord
};
});

So I’ve tried adding to this…

/**
* @NApiVersion 2.0
* @NScriptType ClientScript
*/
define([‘N/currentRecord’, ‘N/ui/dialog’, ‘N/log’, ‘N/record’],

function(currentRecord, dialog, log) {
function saveRecord (){
var objRecord = currentRecord.get();
var costcentre = objRecord.getValue({ fieldId: ‘entityid’})
objRecord.setValue({
fieldId: ‘externalid’,
value: costcentre
});
var newContract = record.create({
type : ‘customrecord_project_combi’
});
newContract.setValue({fieldId : ‘Name’, value :costcentre});
recordID = newContract.Save();
return true;
}
return {
saveRecord: saveRecord
};
});

And I get the error “record is not defined”. This is from the record.create line as if I change record to something else the error mirrors this.

This is probably basic suitescript but I’d be grateful for some pointers.

Other pertinent information would be that this script will run on the NetSuite JOB form and as well as saving and updating this form it would create a new custom “project_combi” record.

Thanks

BullgillRunner Rookie Asked on March 8, 2022 in How To's.
Add Comment
2 Answers
Best answer

 

Your define is missing  record in the second example. It should be:

define([‘N/currentRecord’, ‘N/ui/dialog’, ‘N/log’, ‘N/record’],
function(currentRecord, dialog, log, record) {....

 

Beginner Answered on March 8, 2022.

Thanks, I’d missed that. It gets me past one error, but changing that I still get an error.  I’ve also corrected the uppercase S on Save. I’m now getting

Record Not Saved
Please enter value(s) for: Name

on March 8, 2022.

That suggests to me that your costcentre variable doesn’t have a value. I’d either log it, or hard-code a value you know to be correct to test if it works, then work backwards from there.

on March 9, 2022.

Thanks, it was a simple error. I just needed to put “name” in lowercase!

on March 11, 2022.
Add Comment

Your Answer

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