Search Results for 'script'
-
Search Results
-
I have a checkbox field “Paid”, and a date field “Payment Date”, with their interactions controlled by two script fields. Checking or unchecking “Paid” enters the current date in “Payment Date”, or empties it. Manually entering a date in “Payment Date” checks “Paid”. Deleting the date unchecks “Paid”. Editing the date leaves it alone.
Everything works fine on their own form. Issues arise when I access them through a Link-to-Form field in another form. Some of the behaviour is consistent, some not. One particular oddity is this:
Accessing these records via the Link-to-Form field, editing the date field results in the checkbox being unchecked, which shouldn’t happen. But when I go to the native form I find that the checkbox is still checked. Back to the linked form – the box is certainly unchecked there.
So my investigation of how to get the scripting to work across forms is hampered by this anomaly. Is the box checked or not? I’d appreciate some advice on how to approach this problem.
Here are the scripts from the control fields, in case they shed any light on things:
//Responds to the "Paid" checkbox field being toggled, //by setting or emptying the Payment Date field var paid_id = 'fld-4f9f9ac525964be99ca478bdaee47144'; var paid = record.getFieldValue(paid_id); var thisDate = new Date(); // put the current date into <thisdate> if (paid) { // Use a special version of "setFieldValue" to prevent triggering the Toggle script record.setFieldValue('fld-cf95ec11043d4d2b8dc51d2ab93f177b', thisDate, false); } else { record.setFieldValue('fld-cf95ec11043d4d2b8dc51d2ab93f177b', "", false); }//Responds to the "Payment Date" field getting an entry or being emptied, //by toggling the "Paid" checkbox field var payment_date_id = 'fld-cf95ec11043d4d2b8dc51d2ab93f177b'; var payment_date = record.getFieldValue(payment_date_id); if (payment_date) { record.setFieldValue('fld-4f9f9ac525964be99ca478bdaee47144', "true", false); } else { record.setFieldValue('fld-4f9f9ac525964be99ca478bdaee47144', "false", false); }Any observations very welcome. And, just to note, clicking the refresh button seems to make no difference at any point.
The following script is designed to put the current date into a Payment Date field when a Paid tick-box is checked.
var payment_date_id = 'fld-cf95ec11043d4d2b8dc51d2ab93f177b'; var paid_id = 'fld-4f9f9ac525964be99ca478bdaee47144'; var paid = record.getFieldValue(paid_id); var thisDate = new Date(); if (paid) { console.log(thisDate); record.setFieldValue(payment_date_id, thisDate); } else { console.log("no date"); record.setFieldValue(payment_date_id, ""); }When it’s run as a Form Script, it works fine. When it’s used within a Script Field, the console entries come in as usual, but the Date field doesn’t change, neither to get the Date nor to be emptied when unchecking the field.
If I set the If section to show the output in the Script field itself:
if (paid) { console.log(thisDate); thisDate; } else { console.log("no date"); ""; }the date appears and disappears as it should.
Am I missing something in how Script fields execute actions?