
If you have a sheetworker routine that does stuff in the on-opened event, and that routine changes stuff, on-changed events are NOT generated for those changed things! The problem is only seen when you have a function that runs calculations when the sheet is first opened. <!DOCTYPE html>
<meta charset="UTF-8">
<div class="user-root">
<input name="attr_a" type="number" value="1" style="width: 3em;" >
<input name="attr_b" type="number" value="1" style="width: 3em;" >
<input name="attr_c" type="number" value="1" style="width: 3em;" >
<br>
<input name="attr_r1" type="number" value="0" style="width: 3em;" >
<input name="attr_r2" type="number" value="0" style="width: 3em;" >
</div>
<script type="text/worker">
var calculateR1 = function () {
'use strict';
getAttrs(["a", "b" ], function gar1(values) {
'use strict';
let vals = {};
vals[ "r1"] = parseInt(values[ "a"]) + parseInt( values[ "b"]);
log( "R1: a = " + values["a"]); log( "b = " + values["b"]); log( "r1 = " + vals["r1"]);
setAttrs( vals);
});
};
var calculateR2 = function () {
'use strict';
getAttrs(["c", "r1" ], function gar1(values) {
'use strict';
let vals = {};
vals[ "r2"] = parseInt(values[ "c"]) + parseInt( values[ "r1"]);
log( "r2: c = " + values["c"]); log( "r1 = " + values["r1"]); log( "r2 = " + vals["r2"]);
setAttrs( vals);
});
};
on("change:a change:b", function () {
calculateR1();
});
on("change:c change:r1", function () {
calculateR2();
});
on('sheet:opened',function fnOnSheetOpened(){
'use strict';
log( "sheet opened.");
calculateR1();
});
</script>
When the sheet is opened for the first time, it is supposed to do all the calculations. Now I knew that because of asynchronous issues, R1 is not going to be correct if calculateR2 is run while calculateR1 is still being processed, so I can't just put calculateR1() and calculateR2() both in the sheet:opened event. But I trusted that when R1 was actually written out, it would generate the event that would cause calculateR2 to run. It is not. I don't want to have calculateR1 call calculateR2 directly, because then it would be called twice in every other circumstance! So I don't really know how to work around this. It seems like every solution I try ether has it sometimes not being called, or sometimes being called twice. Using Windows 10 and latest version of chrome.