I am attempting a multi enterprise tool where all companies are sharing the same database. Every application user has a companyID field, linking him to his company's records. Then on every query the results are returned only for his company data.
My current challenge is that I would like the name (and later logo) of his company to be displayed in the header as such:
My first challenge is getting the companyID there. I added a label with value: ${Security.user.companyID}
But as you would expect I am getting an error, because the user has not yet been authenticated.
I assume you would need to test ${Security.IsAuthenticated()} before trying to retrieve the value. I am still trying to figure out how to do that in the pipe, but I suspect it is not going to help, because the label won't necessarily be re-evaluated when the user has logged in.
My second challenge is then to do a query on the Customer by this retrieved ID so that I may display the Company name.
You can set ${Security.IsAuthenticated()} for the Label Visible property - in this case you will not get error if the user is still not authenticated. The same expression can be used in Condition for Data Source Method Invoke action to get customers - the invoke will be executed only if the user us authenticated.
Please check also our CRM tutorial for other techniques similar to these:
The exception you are getting happens because Principal.Identity.Name seems to be null. Normally this should contain the user name of the logged in user. We are not sure why this isn't the case in your application.
I have concluded that the problem is lying with the visible attribute=${Security.IsAuthenticated()} for labels, headings etc. Because the system is attempting to read Principal.Identity.Name before the user has logged in, even though I have added the said visibility check.
But it is working when I embed the label into a container like a Panel or a Card.
So thanks for your help, I am satisfied with having the Label inside a Card.