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

Found the solution to my second issue. I needed lower case for “name”.

Rookie Answered on March 9, 2022.
Add Comment

Your Answer

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