I am working on creating a workflow action script ...
# suitescript
c
I am working on creating a workflow action script to create a note when a checkbox is checked. However I am can't seem to figure out how to get the sales order internal ID. Everything works when I hard code, but I can't figure out a way to source this information. Is it possible to use a WF parameter to pass this information? I couldn't get that to work.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType WorkflowActionScript
 */
 
define(['N/record', 'N/runtime'],
    function(record, runtime) {
        function onAction(context) {

        var note = record.create({
			type: record.Type.NOTE
		});
        note.setValue({fieldId: 'title', value: 'Rev Rec on Hold'});
		note.setValue({fieldId: 'note', value: 'Revenue Recongition was placed on hold'});
        note.setValue({fieldId: 'transaction', value: '123456'});
		note.save();
		
		}

		return {
			onAction : onAction
		};
		
});
b
context.newRecord
c
I tried
Copy code
var salesOrder = context.newRecord;
		var salesOrderID = salesOrder.getValue('internalId');
but I got an error saying that can't create standalone transaction, but it's strange if i used tranId I got a different error
b
what is the full error code
and the code you used to generate the error
c
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType WorkflowActionScript
 */
 
define(['N/record', 'N/runtime'],
    function(record, runtime) {
        function onAction(context) {
          
        var salesOrder = context.newRecord;
		var salesOrderID = salesOrder.getValue('internalId');
          
        var note = record.create({
			type: record.Type.NOTE
		});
        note.setValue({fieldId: 'transaction', value: salesOrderID});
        note.setValue({fieldId: 'title', value: 'Rev Rec on Hold'});
		note.setValue({fieldId: 'note', value: 'Revenue Recongition was placed on hold'});

		note.save();
		
		}

		return {
			onAction : onAction
		};
		
});
You cannot create a standalone note record.
I am guessing cuz newRecord is creating a new SO, but this WF is running on edit of a SO
b
you can try context.newRecord.id
but i think thats supposed to be the same as getting the value of the internal id
unless your code is running for the create type, in which case you need to use after record submit
and use context.newRecord.id
e
Maybe because internalId had a capital (second) i. Should be lower
b
you have a better eye than i do
e
You mean a better i 😆
c
Thank you for the help. I figured it out.
Copy code
var salesOrderID = salesOrder.id
instead of
Copy code
var salesOrderID = salesOrder.getValue('internalid');
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType WorkflowActionScript
 */
 
define(['N/record', 'N/runtime'],
    function(record, runtime) {
        function onAction(context) {
          
        var salesOrder = context.newRecord;
		var salesOrderID = salesOrder.id
          
        var note = record.create({
			type: record.Type.NOTE,
		});
        note.setValue({fieldId: 'transaction', value:salesOrderID});
        note.setValue({fieldId: 'title', value: 'Rev Rec on Hold'});
		note.setValue({fieldId: 'note', value: 'Revenue Recongition was placed on hold'});
		note.save();
		
		}

		return {
			onAction : onAction
		};
		
});
b
Copy code
var note = record.create({
  type: record.Type.NOTE,
  id: salesOrderID
});
you shouldnt need the id there
c
I just realized you also mentioned to use newRecord.id. I was reading the follow up comments and was looking at fixing the capital I and then started googling
oh yea that was one of things i was trying. Once it worked i got excited and started doing other things. Suitescript is still new to me
thanks
e
.id is how I would've done it as well so better that way I believe but essentially they should be equivalent
c
Is it possible to go from a revenue plan > Revenue Arrangement? The idea would be when someone clicks Hold Rev Rec on the plan, it will create a note of it on the revenue arrangement. I would guess the WAS would need to run on the revenue plan and then load the arrangement and create a note.