In Ragic, you can set a Default Value to automatically populate a Date field with the last modification date and time of the entry. However, if you need to automatically populate the field with the last modification date and time of a specific field in the entry, you’ll need to add a script to achieve this.
Please follow this guide to add your script:
Right-click on any sheet name and select Javascript Workflow, or right-click on any tab and select Global Javascript Workflow.
Independent fields :
function setLastModifiedOnField(pathSheet, observeField, recordField) { if (param.getOldValue(observeField) !== param.getNewValue(observeField) || param.isCreateNew()) { var today = new Date(new Date().getTime() + account.getTimeZoneOffset()); function pad2(n) { return n < 10 ? '0' + n : n } var fmtValue = today.getFullYear() + "/" + pad2(today.getMonth() + 1) + "/" + pad2(today.getDate()) + " " + pad2(today.getHours()) + ":" + pad2(today.getMinutes()) + ":" + pad2(today.getSeconds()); var query = db.getAPIQuery(pathSheet); query.addFetchDomains(recordField); var entry = query.getAPIEntry(response.getRootNodeId()); entry.setFieldValue(recordField, fmtValue); entry.save(); } }
Subtable fields :
function setLastModifiedOnSubtableField(pathSheet,observeSubtableKeyField, observeSubtableField, recordField) { var list = param.getSubtableEntry(observeSubtableKeyField); var entry = param.getUpdatedEntry(); var today = new Date(new Date().getTime() + account.getTimeZoneOffset()); function pad2(n) { return n < 10 ? '0' + n : n } var fmtValue = today.getFullYear() + "/" + pad2(today.getMonth() + 1) + "/" + pad2(today.getDate()) + " " + pad2(today.getHours()) + ":" + pad2(today.getMinutes()) + ":" + pad2(today.getSeconds()); for (var i = 0; i < list.length; i++) { if(list[i].getOldValue(observeSubtableField) != list[i].getNewValue(observeSubtableField) && (list[i].getOldValue(observeSubtableField) !== null || list[i].getNewValue(observeSubtableField) !== "" )){ var subRootNodeId = list[i].getSubRootNodeId(); entry.setSubtableFieldValue(recordField, subRootNodeId, fmtValue); entry.save(); } } }
If your sheet URL is https://www.ragic.com/accountname/tabname/1
Independent fields:
Add the following code to the Post-workflow:
setLastModifiedOnField("/tabname/1", Specific Field ID, Record Date Field ID);
To find the Field ID, please refer to this article.
Taking "Sales Order" as an example, refers to the following image and table:
Field | Field Name | Field ID |
---|---|---|
Specific Field | Status | 2000880 |
Record Date Field | Status Update Date | 1001110 |
The code after filling in the corresponding field ID:
setLastModifiedOnField("/tabname/1", 2000880, 1001110);
When creating a new record, if a specific field is empty, the last modification date will still be generated in the record date field after saving. To trigger this only during updates, adjust the code as follows:
if(param.getOldNodeId(Specific Field ID) !== -1){ setLastModifiedOnField("/tabname/1", Specific Field ID, Record Date Field ID); }
Subtable fields:
Add the following code to the Post-workflow:
setLastModifiedOnSubtableField("/tabname/1", Subtable Key Field, Specific Field ID, Record Date Field ID);
Note: Only Subtable fields can be selected as the "Record Date Field".
You can find the Subtable Key Field in the Download Data Dictionary. Refer to the following example, where the Subtable Key Field is 2001138.
For example, as shown in the image above:
Field | Field Name | Field ID |
---|---|---|
Specific Field | Status | 1001111 |
Record Date Field | Update Date | 1001112 |
The code after filling in the corresponding Subtable Key Field and Field ID:
setLastModifiedOnSubtableField("/tabname/1", 2001138, 1001111, 1001112);
When creating a new record, if a specific field is empty, the last modification date will still be generated in the record date field after saving. To trigger this only during updates, adjust the code as follows:
var paramList = param.getSubtableEntry(Subtable Key Field); var list = paramList.toArray(); for(var i = 0; i < list.length; i ++) { if(paramlist[i].getoldnodeid(Specific Field ID) !== -1){ setlastmodifiedonsubtablefield( tabname 1, Subtable Key Field, Specific Field ID, Record Date Field ID); }
Don't forget to save your changes before exiting.
If an error like TypeError: null has no such function "addFetchDomains" in at line number 25 occurs when saving, please check and confirm whether /tabname/1 is correct.
Note: The update date and time will be recorded based on the Company Local Time Zone set in the Company Setting.