'2sxc 13 - Get username and other DNN tokens in formulas/calculations

Is there a way to get the current username in a formula (the v1(data, context) new stuff)? And other DNN tokens as we would on a view.

Current date is easier, since it dependends only on c#, but I can't any documentations for username.



Solution 1:[1]

If you are working with Razor templates, yiu can call and and all DNN methods. Also, while editing a template, the dark left column of the edit screen gives you access to all sorts of snippets that you can use by clicking on them.

Solution 2:[2]

This feature is still experimental and doesn't do much outside of its context in the browser. We've done a few tests and could not reach outside the Angular app's scope (which makes sense). I do believe there are plans wire up things like that. Daniel will probably chime in.

In the mean time, there is no reason you can't write your own API to get the answers you need from the backend. The formulas aren't limited in any way, so there is no reason not to do it like this (assuming writing your own C# 2sxc WebApi code is something you are familiar with):

async function api()
{
  let tmp = await sxc.webApi.fetchJson('/api/2sxc/app/myapp/api/score/progress');
  console.log(JSON.stringify(tmp));
}

Solution 3:[3]

Just fyi: 2sxc 13.10.02 will have a context.sxc which is great for calling APIs, as well as a context.user.id which will give you some user info. Using this you should be able to get this to work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joe Craig
Solution 2
Solution 3 iJungleBoy