I have a List Tickets with a field Client
. This is a user from our AD and displays the name of the user.
We now need to display the country and the location the user resides in to additional fields.
Is it possible to add those fields in the form of calculated fields based on the user in the Client
field? If yes - how?
If not: Could you guide me to the appropriate documentation or resources on how to implement this in the form of code. There are 2 eventhandlers active on this list, handling incoming mails and itemchanges, so I could place the logic there if need be, but right now I desperatly need a starting point, since I am totally lost.
This is a prototype of where I am so far:
SPWeb web = new SPSite("http://myserver/path/sitecollection").OpenWeb();
SPUser user = web.EnsureUser(@"domain\Servdev");
SPListItem item = web.SiteUserInfoList.Items.GetItemById(user.ID);
Console.WriteLine("{0} -- {1}",item.Fields[SPBuiltInFieldId.Department], item.Fields[SPBuiltInFieldId.Office]);
Console.ReadLine();
This displays the name of the fields I want to have, but not the values stored in it and I can't access them. Kind regards
//EDIT:
Apparently, SPBuiltInFieldId.Office
Guid is not valid across the board. So instead you'd have to use item["Office"]
or the localized version of your site. (in my case item["Büro"]
does work too.
But all in all, the answer given by Naim is totally correct. Cheers.