This topic contains 1 reply, has 0 voices, and was last updated by david.smith 7 years, 7 months ago.
-
AuthorPosts
-
April 4, 2017 at 10:24 am #983
girieshgFor a workflow on a custom record, I created a workflow action script that will search for and return the internal ID of a GL account based on some criteria. On the script record If I set the Return Type field to List / Account and the List / Account field to “Account”, I get a SuiteScript error – “Invalid return type for custom action”.
However, the script runs fine with no errors, and if I try to directly set the field value from the script (without trying to return a value through the action / workflow) the field value is set correctly.
What am I doing wrong?
Here’s my workflow action script –
Code:
/**
* @NApiVersion 2.x
* @NScriptType workflowactionscript
*/
define([‘N/search’],function(search) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord – New record
* @param {Record} scriptContext.oldRecord – Old record
* @Since 2016.1
*/
function onAction(scriptContext) {
try{
var recId = scriptContext.newRecord.getValue({fieldId: ‘custrecord_parentrecord’});
var value = null;
log.debug(‘Search Filter Value’, recId);
var accountSearch = search.create({
type: ‘customrecord_deal’,
filters: [
{name: ‘internalid’, operator: ‘anyof’, values: [recId]}
],
columns: [
{name: ‘custrecord_defaultaccount’, join: ‘custrecord_basetype’, label: ‘Default Account’}
]
});
accountSearch.run().each(function(sResult){
value = sResult.getValue({name: ‘custrecord_defaultaccount’, join: ‘custrecord_basetype’});
log.debug(‘Returned value’, value);
return value;
});
//scriptContext.newRecord.setValue({fieldId: ‘custrecord_account’, value: value}); // THIS WORKS
} catch(ex) {
log.error(ex.name, ex.message);
}
}return {
onAction : onAction
};});
Screenshots of debug log, script record, and error message attached.
This is a cached copy. Click here to see the original post. -
April 4, 2017 at 10:27 am #984
david.smithThe “return value;” is the return for the .each function so you’re not actually returning anything. You need to set your var and exit the foreach before returning your value.
girieshg replied on 04/04/2017, 10:32 AM: That worked. Thanks a bunch.
-
AuthorPosts
You must be logged in to reply to this topic.