Can I assign JavaScript macro results to a variable?

I’ve added DNA match data to Memory Keeper (example importing 23andme DNA match file). I’m now writing some macros to review / report data. Two of these macros return a list of list people tiddlers, one a paternal list of tiddlers, the other maternal. The list shows know paternal/maternal Haplogroups from DNA data.

<$macrocall name=“GetPaternalListHaplogroups” person={{!!title}} />

This macro would be used on every person tiddler (in an ViewTemplate). It would return something like:

[[Smith, John]] [[Smith, William]]

The list of tiddlers the macro returns I now want to use in a list filter. I could do this if I could get the results in a variable.

In similar macros I had saved the results to a temporary tiddler. I was trying to avoid that here as it would potentially generate numerous temporary tiddlers.

How can solve this? Thanks,

Craig

Since you are already in javascript, consider implementing it as a filter operator instead of a macro. A filter operator is slightly more tricky to think about than macros, but there are so many example operators that it might be straightforward to find one to copy and modify.

You’d need to decide whether to read your “person” as a filter parameter or read “person” as input titles.

If input titles, then you can base your code off of the addprefix operator. You’d need to call the source function as here: https://tiddlywiki.com/#%24%3A%2Fcore%2Fmodules%2Ffilters%2Faddprefix.js. However, you would not need operator.operand since your operator would not have a parameter. The title variable would contain your “person”.

If filter parameter, then you can refer to the else clause in https://tiddlywiki.com/#%24%3A%2Fcore%2Fmodules%2Ffilters%2Ftitle.js. You would be ignoring input titles, so you don’t need to call the source function. This seems like a less flexible approach but it is hard to say without knowing the full context of your macros.

Having it as a filter operator makes it easy to get the results in a variable.

1 Like

I wrote a sort filter some time ago, so I guess I should have worked that out myself. Brilliant! Thank you.

This works as expected.

Of course in 5.3.0 custom operators via the function operator are trivial.

There are also why to address you OT in regular TiddlyWiki script but since you have a solution I will not address it in detail.

  • you would use the wikify widget just in time to render the result of the macro call before use.