Connector with optional parameters not working

31 views
Skip to first unread message

chadgw...@gmail.com

unread,
Jul 5, 2018, 10:29:01 PM7/5/18
to ImSmart.tech
Hi there. I have a Connector with an optional (not marked as Mandatory) parameters. I noticed that my triggers that refer to the connector is erroring as such:
Trigger : Action script error: ReferenceError: _value2 is not defined at Script Document [8] [temp]:3:5 -> if (_value2)

This is referencing _value2 when it's left blank in the trigger. It used to work just fine. Is there a new syntax or way to double check if a parameter has been provided?

ImSmart.tech

unread,
Jul 8, 2018, 5:23:21 PM7/8/18
to ImSmart.tech
You need to check if _value2 is defined (e.g. _value2 !== undefined).

See the code in the IFTTT module for reference.

Paul

chadgw...@gmail.com

unread,
Jul 8, 2018, 5:39:47 PM7/8/18
to ImSmart.tech
That doesn't work. For example, now I get:
 Action script error: ReferenceError: _value2 is not defined at Script Document [8] [temp]:3:5 -> if (_value2 !== undefined)

Something changed because I used to just be able to call my method as such (which is valid JS but now I'm getting a ReferenceError just by referencing _value2 when it isn't passed in):
service.writePinValue(_pin, encodeURI(_value1), encodeURI(_value2), encodeURI(_value3), encodeURI(_value4));

Paul Dubé

unread,
Jul 8, 2018, 8:41:32 PM7/8/18
to ImSmart.tech
Strange indeed. No new version has been pushed since April.
I cannot see anything wrong in your code. I still cannot see why you get an error. You'll need to give me some time to dig for this one...

When you say that it worked before you mean that you did not change any code?

chadgw...@gmail.com

unread,
Jul 8, 2018, 11:28:47 PM7/8/18
to ImSmart.tech
I appreciate your help Paul. 
I've tried unsuccessfully multiple times for more than a month so it's hard for me to tell when it last worked but I think on 6/23 was the last successful use. The code hasn't changed until recently where I was trying to play with the connector to see if it would work. If I don't reference any of the optional parameters that I don't pass a value through (within my trigger), it works. 

ImSmart.tech

unread,
Jul 30, 2018, 11:48:25 AM7/30/18
to ImSmart.tech
Hi Chad,

Since you're passing arguments to your function, it needs to have valid arguments. If your arguments are not mandatory you still need to assign them some value.

You could do something like this in your action script before calling your connector action:

if (typeof _value2 === 'undefined')
    _value2 = '';
    
if (typeof _value3 === 'undefined')
    _value3 = '';
    
if (typeof _value4 === 'undefined')
    _value4 = '';

chadgw...@gmail.com

unread,
Jul 30, 2018, 5:01:23 PM7/30/18
to ImSmart.tech
Thank you! That did the trick. Do you know what changed perhaps in the configuration of Node (I'm assuming that's the language under the covers) to require this syntax? Previously, this worked without needing to assign values to every argument. 

ImSmart.tech

unread,
Jul 30, 2018, 7:13:00 PM7/30/18
to ImSmart.tech
Nothing changed in the configuration. Something must have been different from your code before.
It's ClearScript that runs behind.

Paul
Reply all
Reply to author
Forward
0 new messages