Question
There is a cron job that sends a reminder in the form of a table via email every day.
The code looks like this:
=: if(condition: $sel != $#lc; then: $send)
sel: selectList(table: 'requests'; field: 'id'; where: 'status' = "open")
send: emailSend(to: $userssend; title: "Daily report on open requests"; body: $body)
userssend: select(table: 'users'; field: 'email'; where: 'roles' = 4)
body: textByTemplate(template: "template_name"; data: $data)
data: rowCreate(field: "table" = $row)
row: rowCreate(field: "template" = "inner_template_row"; field: "data" = $rowlist)
rowlist: selectRowList(table: 'requests'; sfields: json`["customer","suppliers","offers"]`; field: 'number'; field: 'application_deadline'; field: 'request_sent'; field: 'proposal_client'; where: 'status' = "open"; order: 'number' asc)
application_deadline
, request_sent
, proposal_client
are fields of type "date" and if these fields contain null, it is necessary to substitute a value in the template in the cells as "Empty"/"No"/"---" (anything but "").
Answer
Since the fields application_deadline
, request_sent
, proposal_client
are Date type fields and are stored in Totum in the Y-m-d format, it makes sense to format them into a human-readable format accepted in your region.
This can be done using the dateFormat function:
=: if(condition: $sel != $#lc; then: $send)
sel: selectList(table: 'requests'; field: 'id'; where: 'status' = "open")
send: emailSend(to: $userssend; title: "Daily report on open requests"; body: $body)
userssend: select(table: 'users'; field: 'email'; where: 'roles' = 4)
body: textByTemplate(template: "template_name"; data: $data)
data: rowCreate(field: "table" = $row)
row: rowCreate(field: "template" = "inner_template_row"; field: "data" = $dateformat)
dateformat: dateFormat(date: $rowlist; format: "d.m.Y"; keys: json`["application_deadline","request_sent","proposal_client"]`; recursive: true; replace: "Empty")
rowlist: selectRowList(table: 'requests'; sfields: json`["customer","suppliers","offers"]`; field: 'number'; field: 'application_deadline'; field: 'request_sent'; field: 'proposal_client'; where: 'status' = "open"; order: 'number' asc)
For the dateFormat function, you can specify a list of keys that need to be processed in the keys parameter, set the format, indicate that the entire array should be processed by passing recursive: true, and use the replace parameter to specify the value to replace "" and null.