HI, <#C29HQS63G|> I am attempting to add a User No...
# suitescript
d
HI, #C29HQS63G I am attempting to add a User Note to a Custom Record. Appears to be working to create the note but they are not visible on the Custom Record itself. When creating the Note without the Custom Record reference properties I see an error that a Standalone User Note cannot be created. Therefore I am led to suspect the view on Custom Records for pulling in associated Notes is the problem. If I look at a list of User Notes I see the Notes but I am unable to determine what each note is associated to. I will attach several screenshots into the thread for this post. Please, also see the Snippet I will include for debugging the same code. Thanks in advance!
Copy code
require(['N/runtime',
	'N/search',
	'N/render',
	'N/record'],
function(runtime, search, render, record) 
{
function addUserNote (options) {
		var note = record.create({ 'type' : record.Type.NOTE });
		var finalContent = '';
		if ('title' in options) {
			finalContent += runtime.getCurrentScript().id;
			finalContent += ':';
		} // else this will become the title so skip
		finalContent += runtime.getCurrentScript().deploymentId;
		if ('note' in options) {
			finalContent += ' ';
			finalContent += options['note'];
		} // else no note but use script details
		if ('transactionID' in options) {
			note.setValue({ 'fieldId' : 'transaction', 'value' : options['transactionID'] });
		} else if ('customerID' in options) {
			note.setValue({ 'fieldId' : 'entity', 'value' : options['customerID'] });
		} else if ('recordID' in options) {
			note.setValue({ 'fieldId' : 'record', 'value' : options['recordID'] });
			if ('recordType' in options) note.setValue({ 'fieldId' : 'recordType', 'value' : options['recordType'] });
		}
		if (!('transactionID' in options) // transaction user-note
			&& !('customerID' in options) // customer user-note
			&& !('recordID' in options) // custom-record user-note
			&& !('recordType' in options)) throw finalContent; // should not happen but just as defensive code
		if (finalContent.length > 4000) {
			finalContent = finalContent.substring(0, 4000);
		} // else the entire note fits the maximum User Note memo length
		note.setValue({ 'fieldId' : 'note', 'value' : finalContent });
		if (!('title' in options)) { // default the title
			options['title'] = runtime.getCurrentScript().id
		} // else use the title provided
		note.setValue({ 'fieldId' : 'title', 'value' : options['title'] });
		note.setValue({ 'fieldId' : 'direction', 'value' : 1 }); // i.e. "Incoming"
		note.setValue({ 'fieldId' : 'notetype', 'value' : 7 }); // i.e. "User" - Setup > Sales > CRM Lists > New > Note Type
		return note.save();
	}
	var snapshotID = 3380709;
	var recordType = 'customrecord_v4_render_snapshot';
	var recordTypeID = 807;
	addUserNote({
		'title' : 'Sample 1',
		'recordType' : recordType,
		'recordID' : snapshotID,
	});
	addUserNote({
		'title' : 'Sample 2',
		'recordType' : recordTypeID,
		'recordID' : snapshotID,
	});
	addUserNote({
		'title' : 'Sample 3',
		'recordID' : record.load({ // reuse custom record
				'type' : recordType,
				'id' : snapshotID	}),
	});
});
Sample 1 and Sample 2 create just fine. Sample 3 I attempt to pass the record itself in and that is when I see the following error: {"type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"You have entered an Invalid Field Value null for the following field: record","stack":["anonymous(N/record/recordService.js)","addUserNote(adhoc$-1$debugger.user:42)","anonymous(adhoc$-1$debugger.user:57)","anonymous(adhoc$-1$debugger.user:1)"],"cause":{"type":"internal error","code":"INVALID_FLD_VALUE","details":"You have entered an Invalid Field Value null for the following field: record","userEvent":null,"stackTrace":["anonymous(N/record/recordService.js)","addUserNote(adhoc$-1$debugger.user:42)","anonymous(adhoc$-1$debugger.user:57)","anonymous(adhoc$-1$debugger.user:1)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
@erictgrubaugh DEBUG SuiteScript shared above
e
recordtype
must be numeric, not the string
"customrecord_blah"
, and
record
must be a string,
"3380709"
not
3380709
. Force
snapshotID
to be a string, use
recordTypeID
, and it should work
d
OHHH, ok
trying again... thanks again
e
If it doesn't, then I'm not sure what's going on. Took me forever to work this out. Not sure why Notes behave so differently than any other record
🤓 1
👍 1
d
Tried every combo of string, number, full-string name, etc. still not getting visible notes on the Custom Record. They all appear to create fine but none onto the records list of User Notes.
I am pulled onto something else right now, but I appreciate the responses @erictgrubaugh if I figure it out later I will respond back with what my issue was.
@mkachline FYI
b
incorrect capitalization of recordType in the fieldId
otherwise the second attempt looks correct, set the
recordtype
to the internal id number of the custom record type and the
record
to the internal id number of the particular custom record
e
record
must be a string in my experience
It's a numeric value, but string type, e.g.
"123"
b
i too prefer strings, sometimes weird things happen with numbers and their string representations
e
Yeah this is specifically for Notes. It took me weeks to figure out this problem a few months back
Of course, that doesn't mean it hasn't changed since then ...