0

Can a variable be used like this code in the macro expressions to retrieve values dynamically?

I am trying the code below which return as null.

var indexId = 45;

return CMSContext.Current.GlobalObjects.Users[indexId].DisplayName;
Consp
  • 5
  • 4
  • Can you give more context into where you are trying to use this macro and the exact code you are using? – probrandono Mar 08 '22 at 19:21
  • I was trying to retrieve the user name dynamically. I figured I just needed to write that code on the same line and it worked. {%indexId = 45;return CMSContext.Current.GlobalObjects.Users[indexId].DisplayName;%} – Consp Mar 11 '22 at 16:28

2 Answers2

0

Yes, please see the macro syntax documentation

jurajo
  • 937
  • 5
  • 5
0

I figured that the code should be on the same line. Earlier I was declaring the variable in separate line. So this works now

indexId = 45;return CMSContext.Current.GlobalObjects.Users[indexId].DisplayName;
Consp
  • 5
  • 4