Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method for Collection of Method Attributes with Time and Date
Published On: October 11, 2022

Below is a utility method that will return a collection of attributes for all of the methods in the current database along with adding on the time and date of the last committed modification for Project Mode only.

// getMethodAttrWDateTime
// Returns a collection containing method attributes of the database including the name, date, and time of the last commited modification.
// $0 ($c_methodOBs) - Collection of method attributes including the name, date, and time.
// -----------------------------------------------------------

#DECLARE->$c_methodOBs : Collection

If (Is compiled mode=False)
   var $t_docPath; $t_methodAttr; $t_curMethod : Text
   var $o_methodAttr : Object
   var $c_methodAttr : Collection
   $t_docPath:=Folder separator+"Project"+Folder separator+"DerivedData"+Folder separator+"methodAttributes.json"
   $t_methodAttr:=Document to text($t_docPath)
   $o_methodAttr:=JSON Parse($t_methodAttr).methods
   For each ($t_curMethod; $o_methodAttr)
   End for each
   $c_methodOBs:=OB Values($o_methodAttr)
End if

The method works by parsing the methodAttributes.json file located at
{Project Database Root}\Project\DerivedData\
The file contains a list of all of the methods of the project database in JSON format with the attributes and a timestamp of the last commited modification.
The method will return a collection of each method's object of attributes and add on the method's name, date converted from the timestamp and time converted from the timestamp.

Example resulting element of the resulting collection:

The results can then be interacted with using Collection functions such as a query for the modified methods in the past five hours.
Below is a simple example of utilizing the utility method:
var $c_methodOBs; $c_recentModMethods; $c_recentModMethodsNames : Collection


$c_recentModMethods:=$c_methodOBs.query("date >= :1 & time >= :2"; Current date; Current time-?05:00:00?)


In the example, all of the methods are listed in $c_methodOBs.
A query was performed on the collection to get the recently modified methods in the past five hours and stored into $c_recentModMethods.
Lastly, the extract function was used to get a collection of only the names of the recently modified methods and stored into $c_recentModMethodsNames.