@Formula Magic

How often have you created views to return a concatenated value as a result of a @DBLookup? You normally create a new column and add something like this as a column value:

fieldname1 +"~"+ fieldname2 + ...

The complexity of this formula increases with the number of items you like to concatenate.
And it gets even more complex if you want to build a view to return all items of a document ( except a few ) as JSON style data.

Then you would have to write a formula similar to this:

"{ \"" + "count\" :" + @Text(count) + " \"" + "Author\" :" + Author + ... +"\}"

A little @formula magic can make this work much easier

Simply put this formula snippet into a view column.

_exclude:="$FILE":"$Fonts":"Form":"$UpdatedBy":"$Revisions";
_fld:=@Trim(@ReplaceSubstring(@DocFields;_exclude;@Nothing));

"{"
+ @Implode (
@Transform (
_fld; "_fn" ; "\"" + _fn + "\":\"" + @Text ( @GetField ( _fn) ) + "\"" ) ; "," ) +
"}"

@DocFields gets all fields of the underlying document and @Transform and @Implode concatenate the fieldnames and according values. The result looks like this:

{
"fieldname1": "value",
"fieldname2": "value",
"fieldname3": "value",
...
}

Now you can use this view column as a JSON datasource …

3 thoughts on “@Formula Magic

  1. Cool. Nice tip for domino xpages / web development Thanks a lot.

    I guess the classic notes DbLookups / Picklists etc. would be running into still-not-fixed 32K/64K size limits, though.

  2. @GetField returns the first value only for multi-valued fields. Any work around for that?

    BTW…. Great tip… 🙂

Comments are closed.