Search code examples
javascriptif-statementzapier

Javascript If statements in Zapier Code, "must return a single object or array of objects."


I am trying to do a simple If function in zapier that returns a number between 1-10 based on another number input. for example if the number input is equal to 7200000 it should output 2. so far i have this:

if (inputData.num === '7200000') {
  output = '2';
} else {
  output = inputData.num;
} 

This is giving me the error "You must return a single object or array of objects."

Can anyone help with this?

Thanks in advance :)


Solution

  • I found the solution,

    Input Data: ms = TimeEstimate
    var d = new Date(1000*Math.round(inputData.ms/1000));
    function pad(i) { return ('0'+i).slice(-2); }
    var str = d.getUTCHours() + ',' + pad(d.getUTCMinutes());
    console.log(str); 
    
    output = [{str}];