I'm trying to set up a calculation to estimate work hours for jobs. To do this I need the calculation to add up all the completed fields. Each field represents a number of tasks required for a section of the job, however each of these sections have an inherit set up time, so that for "Floors" for example the set up time is 1, so if the number of tasks equals 'n' the total time will equal 'n+1'. I'm trying to create a script so that if a field value is greater than 0 then the value 'n' will be equal to 'n+1' but if the value 'n'=0 it will still be equal to 0.
Below is currently what I’m working with, it seems to work ok for a 3 or so values but not the 23 values i need it to work for.
var a = this.getField("Floors");
var b = this.getField("Plant_Rooms");
var c = this.getField("Zones");
var d = this.getField("VAVs");
var e = this.getField("AHUs");
var f = this.getField("ACUs");
var g = this.getField("MiscFans");
var h = this.getField("AirOther");
var i = this.getField("Chillers");
var j = this.getField("CoolingTowers");
var k = this.getField("Cogen");
var l = this.getField("CHWOther");
var m = this.getField("Boilers");
var n = this.getField("HeatExchange");
var o = this.getField("HHWOther");
var p = this.getField("MPower");
var q = this.getField("MWater");
var r = this.getField("MGas");
var s = this.getField("MOther");
var t = this.getField("Security");
var u = this.getField("Lighting");
var v = this.getField("Fire");
var w = this.getField("OtherOther");
if (a.value==0)
var Floors = 0
else
var Floors = 1
if (b.value==0)
var Plant_Rooms = 0
else
var Plant_Rooms = 1
if (c.value==0)
var Zones = 0
else
var Zones = 1
if (d.value==0)
var VAVs = 0
else
var VAVs = 0.5
if (e.value==0)
var AHUs = 0
else
var AHUs = 2
if (f.value==0)
var ACUs = 0
else
var ACUs = 0.5
if (g.value==0)
var MiscFans = 0
else
var MiscFans = 1
if (h.value==0)
var AirOther = 0
else
var AirOther = 1
if (i.value==0)
var Chillers = 0
else
var Chillers = 2
if (j.value==0)
var CoolingTower = 0
else
var CoolingTower = 1
if (k.value==0)
var Cogen = 0
else
var Cogen = 1
if (l.value==0)
var CHWOther = 0
else
var CHWOther = 1
if (m.value==0)
var Boiler = 0
else
var Boiler = 2
if (n.value==0)
var HeatExchange = 0
else
var HeatExchange = 1
if (o.value==0)
var HHWOther = 0
else
var HHWOther = 1
if (p.value==0)
var MPower = 0
else
var MPower = 1
if (q.value==0)
var MWater = 0
else
var MWater = 1
if (r.value==0)
var MGas = 0
else
var MGas = 1
if (s.value==0)
var MOther = 0
else
var MOther = 1
if (t.value==0)
var Security = 0
else
var Security = 1
if (u.value==0)
var Lighting = 0
else
var Lighting = 1
if (v.value==0)
var Fire = 0
else
var Fire = 1
if (w.value==0)
var OtherOther = 0
else
var OtherOther = 1
event.value= this.getField("Platform").value + this.getField("Floors").value + Floors + this.getField("Plant_Rooms").value + Plant_Rooms + this.getField("Zones").value + Zones + this.getField("VAVs").value + VAVs + this.getField("AHUs").value + AHUs + this.getField("ACUs").value + ACUs + this.getField("MiscFans").value + MiscFans + this.getField("AirOther").value + AirOther + this.getField("Chillers").value + Chillers + this.getField("CoolingTowers").value + CoolingTowers + this.getField("Cogen").value + Cogen + this.getField("CHWOther").value + CHWOther + this.getField("Boilers").value + Boilers + this.getField("HeatExchanger").value + HeatExchanger + this.getField("HHWOther").value + HHWOther + this.getField("MPower").value + MPower + this.getField("MWater").value + MWater + this.getField("MGas").value + MGas + this.getField("MOther").value + MOther + this.getField("Security").value + Security + this.getField("Lighting").value + Lighting + this.getField("Fire").value + Fire + this.getField("OtherOther").value + OtherOther
Any help would be much appreciated.
Your script can be corrected and simplified a bit to:
// Custom calculate script
(function () {
// Get field values, as numbers
var a = +getField("Floors").value;
var b = +getField("Plant_Rooms").value;
var c = +getField("Zones").value;
var d = +getField("VAVs").value;
var e = +getField("AHUs").value;
var f = +getField("ACUs").value;
var g = +getField("MiscFans").value;
var h = +getField("AirOther").value;
var i = +getField("Chillers").value;
var j = +getField("CoolingTowers").value;
var k = +getField("Cogen").value;
var l = +getField("CHWOther").value;
var m = +getField("Boilers").value;
var n = +getField("HeatExchange").value;
var o = +getField("HHWOther").value;
var p = +getField("MPower").value;
var q = +getField("MWater").value;
var r = +getField("MGas").value;
var s = +getField("MOther").value;
var t = +getField("Security").value;
var u = +getField("Lighting").value;
var v = +getField("Fire").value;
var w = +getField("OtherOther").value;
// Add extra value if not zero
a = a === 0 ? a : a + 1;
b = b === 0 ? b : b + 1;
c = c === 0 ? c : c + 1;
d = d === 0 ? d : d + 0.5;
e = e === 0 ? e : e + 2;
f = f === 0 ? f : f + 0.5;
g = g === 0 ? g : g + 1;
h = h === 0 ? h : h + 1;
i = i === 0 ? i : i + 2;
j = j === 0 ? j : j + 1;
k = k === 0 ? k : k + 1;
l = l === 0 ? l : l + 1;
m = m === 0 ? m : m + 2;
n = n === 0 ? n : n + 1;
o = o === 0 ? o : o + 1;
p = p === 0 ? p : p + 1;
q = q === 0 ? q : q + 1;
r = r === 0 ? r : r + 1;
s = s === 0 ? s : s + 1;
t = t === 0 ? t : t + 1;
u = u === 0 ? u : u + 1;
v = v === 0 ? v : v + 1;
w = w === 0 ? w : w + 1;
// Calculate field value
event.value = +getField("Platform").value + a + b + c + d + e + f + g
+ h + i + j + k + l + m + n + o + p + q + r + s + t + u + v + w;
})();
Also, it looks like you have a typo. Is it "HeatExchange" or "HeatExchanger"?