JayFF
Posts: 119
Joined: Fri Oct 03, 2014 1:03 am
Location: USA
Contact: Website

Device Script 'OR' Fails

Fri Jun 10, 2016 1:28 am

Hi All,

I tried to create a device mapping script in the Site Administrator ... Device Mapper Template ... Scripts section. For some reason, the script could not correctly interpret the JavaScript 'OR' operator (||). Here is the script:

var input4 = fields.get('BroomState', 0)
var input1 = fields.get('SanderState', 0)
var input2 = fields.get('PlowState', 0)
if (input4 > 0 || input1 > 0 || input2 > 0)
{
return true;
}
return false;

I found an online JavaScript evaluator (http://www.w3schools.com/js/tryit.asp?f ... parison_or) and the comparison worked as expected. However when I tested the script from a device, it only returned true if input4 was greater than 0. It seemed to not evaluate the other two values. I used a terminal window to confirm that my inputs were being sent correctly from the device. I was able to fix the problem by changing the || statement into a series of if statements checking each value in turn:

var input4 = fields.get('BroomState', 0)
var input1 = fields.get('SanderState', 0)
var input2 = fields.get('PlowState', 0)
if (input1 > 0)
{
return true;
}
if (input2 > 0)
{
return true;
}
if (input4 > 0)
{
return true;
}
return false;

Has anyone else seen this?

Cheers,
Jay

J. F. Florey

Return to “GpsGate for Developers”