Invalid JavaScript value of type [Lnumber;.

101 views
Skip to first unread message

Alexander

unread,
Nov 11, 2019, 8:24:17 AM11/11/19
to Google Ads Scripts Forum
I get a strange error when executing following code.
 
Invalid JavaScript value of type [Lnumber;. (file Code.gs, line 9)
 
function main(){
  MccApp.accounts().withLimit( 1 ).executeInParallel( 'processAccount', 'finalProcessing' );
}

function processAccount(){
}

function finalProcessing( arg ){
  var typeOfArgument = typeof arg;
}


Google Ads Scripts Forum Advisor

unread,
Nov 11, 2019, 2:57:12 PM11/11/19
to adwords-scripts+apn2wqchzqdcdy5b...@googlegroups.com, adwords-scripts+apn2wqchzqdcdy5b...@googlegroups.co, adwords...@googlegroups.com
Hi Alexander,

The optional callback function you are using 'finalProcessing' expects an array of execution result objects that should be passed from the 'processAccount' function. Your processAccount function does not have any return value, which is required for the optional callback function. Please see this guide for more information.

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UJaGDN:ref

Alexander

unread,
Nov 12, 2019, 5:44:43 AM11/12/19
to Google Ads Scripts Forum
Thank you. I added a return value to the processAccount function. Same result. It's just a bad idea to use the "typeof" operator on the argument of the callback function. Maybe I can use instanceof or duck typing to determine the type of the argument. Thank you.
 
function main(){
  MccApp.accounts().withLimit( 1 ).executeInParallel( 'processAccount', 'finalProcessing' );
}

function processAccount(){
  return '';

}

function finalProcessing( arg ){
  var typeOfArgument = typeof arg;
}

Google Ads Scripts Forum Advisor

unread,
Nov 12, 2019, 2:40:21 PM11/12/19
to adwords-scripts+apn2wqchzqdcdy5b...@googlegroups.com, adwords-scripts+apn2wqchzqdcdy5b...@googlegroups.co, adwords...@googlegroups.com
Hi Alexander,

Although that typeof error does get thrown regardless of the return value, I'm not sure there is much use in getting the type of the callback argument, since it will always be an array of execution results. However, in the code below:

function main(){
  MccApp.accounts().withLimit( 2 ).executeInParallel( 'processAccount', 'finalProcessing' ); //Using 2 accounts in this example
}

function processAccount(){
  return 'test';
}

function finalProcessing( arg ){
  
  for(var i = 0; i < arg.length; i++) {   
    Logger.log(typeof arg[i]);      
    Logger.log(typeof arg[i].getReturnValue());
  }
}

The log is:

object
string
object
string

Since, arg[i] is an execution result object, the typeof operator returns 'object'. You need to use the getReturnValue method on the execution result to get the actual value of that result. 
Reply all
Reply to author
Forward
0 new messages