Macro in Web part visible field

Vasyl Chepil asked on April 26, 2016 10:51

I'm using next macro in web part visible field

{% CMSContext.Current.GlobalObjects.Users.Where("UserID="+ToInt(QueryString["UserId"], 0 )).FirstItem.IsExpertIn != "" #%}

but it doesn't work if IsExpertIn returns null.

How i need to modify my macro to handle situation when IsExpertIn returns null?

Recent Answers


Anton Grekhovodov answered on April 26, 2016 14:54 (last edited on December 10, 2019 02:30)

Hi Vasyl,

I think if IsExpertIn is string value, you should use:

{% !string.IsNullOrEmpty(CMSContext.Current.GlobalObjects.Users.Where("UserID="+ToInt(QueryString["UserId"], 0 )).FirstItem.IsExpertIn) |(identity)GlobalAdministrator%}
1 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on April 26, 2016 15:57 (last edited on December 10, 2019 02:30)

Following code covers both null and empty string values:

{% GlobalObjects.Users.Where("UserID="+ToInt(QueryString.GetValue("UserId"),0)).FirstItem.IsExpertIn.ToString()!="" |(identity)GlobalAdministrator%}
2 votesVote for this answer Mark as a Correct answer

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