Date Calculations in Apps Scripts
This is probably a very simple solution, but I've been banging my head on this for two days.
I need to populate a date field in a child table with a date stored in a parent record minus 14 at the time the child record is created via Apps Script. Not all child records link to the same parent table, and the child date field needs to be editable, so a calculated date field in the child table is not an option.
I have attempted a calculated datesub in the parent to subtract 14 from the source field, then use the calculated field in the script. The script saves with no errors, but the value of the calculated field is not populating on the child record. I have tested by referencing the source date field (not calculated) and it populates with no issues.
It looks like calculated fields cannot be used in Apps Scripts, so looking for an example that will handle the calculation directly within the script itself.
Parent Date = source (standard date field)
Due Date = source - 14 (I tried a datesub calc date, but not populating in the child)
Child Date = Parent Due Date value (standard date field populated with value from parent Due Date field)
Here is my script that is not working:
addChild ("Tasks", "PPR Task",
[ 'Due Date': currentValues["Due Date calc"], ]) }
Thanks - I checked the KB but there is no reference to dates, and the Groovy site is too confusing.
John McGarvey commented
This helped - it got me on the right path and is now working.
Thanks so much !
Andrew Forrester commented
I've had my own similar issues. I think the issue is that Apps Scripts does not allow you to access calculated fields (http://help.trackvia.com/forums/262244-trackvia-api-app-scripts/suggestions/19145731-which-field-types-are-not-supported-by-app-scripts).
A triggered field might solve the issue, or you something like this:
Date created = currentValues["Created"] as Date
Date dueDate = created - 14
addChild("Tasks", "PPR Task", [ "Due Date": dueDate ])
Hope that helps..