Variable in Macro Expression

Novice User asked on March 8, 2022 16:32

I have a macro expression and wants to assign a variable so it can resolve based on the variable value. So far I am unable to find a way. Can any one please help me to see what I am missing ?

So for example I want to display name of a user Id 100, writing code like this works perfect CMSContext.Current.GlobalObjects.Users[45].DisplayName

but this does not work

int IDNumber = 45;
return CMSContext.Current.GlobalObjects.Users[IDNumber].DisplayName;

How can I make this work?

Correct Answer

vasu yerramsetti answered on March 9, 2022 03:42

Please use the following -

{% i=45;CMSContext.Current.GlobalObjects.Users[i].DisplayName#%}

You can also test Macro expression on System- Refer this for Macro syntax from System--> Macros-->Console

https://docs.xperience.io/k12sp/macro-expressions/macro-syntax#Macrosyntax-Compoundexpressionsanddeclaringvariables

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.