locked
Coding best practice display name vs internal name in itemUpdated event receiver RRS feed

  • Question

  • Hi,

    In an itemupdated event receiver, when referring to list fields, is it better to use the field's internal name, or its display name?

    Is there a clear guideline or best practice, or is this a subjective discussion?

    Thanks in advance for your replies

    Tuesday, March 18, 2014 3:56 AM

Answers

  • Hi Jorge,

    One of the best practice I follow is Repository pattern for list access, on that scenario I always use Internal Names.

    The rational behind this decision is Fristly, I will have full control, Secondly I need not to worry about column names changes by business/endusers through SharePoint UI which I cannot control of. Though we had governance in place and trained the users, still no avail, users will go and change the column names. 

    Thirdly, My code will not break when there is a display name change. One of my client was too UI rather than business logic, since the enduser are high profile managers, spacing between columns and readabiltily are first class citizen.  Those changes that we made to the list library did not affect our code and the application was running without code refactoring.

    Backto your question, I will use Internal names in my CAML query to minimize error as follows

    item["internalName"]

    Your question is subjective, I have not seen any best practices on this subject, being said that, if you are looking for best practice and guidance I would suggest you to start here -

    SharePoint 2010 Guidance http://msdn.microsoft.com/en-us/library/ff770300.aspx ( no idea on SP 2013 guidance availablity)

    Go through the code and doc, You will get the design rational behind each choice.


    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you


    Tuesday, March 18, 2014 3:51 PM

All replies

  • Hi Jorge,

    it really depends upon the API that you are using, and on whether the fields are created by you (or team) or SharePoint OOTB fields

    here are few discussion on this topic -

    http://tomblog.insomniacminds.com/2008/01/25/sharepoint-internals-internalname-versus-displayname/

    http://alexangas.com/blog/2008/09/internal-name-vs-display-name/


    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

    Tuesday, March 18, 2014 4:40 AM
  • Hi Ram,

    Thank you for your reply, and thank you for the links.

    So here's some more info on the context:

    I'm deploying a server side solution package, that includes a site feature, all using server side OM.

    When activated, among other things, this feature adds an itemUpdating event receiver to a particular list that was created by a Power user.

    This event receiver determines that whenever a user changes one of a few key fields in list A,  some of these fields are synchronized to some list B items.

    When looking up the values of these fields in either list, would you use item["internalName"] or item["DisplayName"] (and item.Field["DisplayName"].InternalName for CAML Queries) ?

    Do you have a personal preference? Is there a clear guideline or best practice, or is this a subjective discussion?

    Tuesday, March 18, 2014 6:32 AM
  • Hi Jorge,

    One of the best practice I follow is Repository pattern for list access, on that scenario I always use Internal Names.

    The rational behind this decision is Fristly, I will have full control, Secondly I need not to worry about column names changes by business/endusers through SharePoint UI which I cannot control of. Though we had governance in place and trained the users, still no avail, users will go and change the column names. 

    Thirdly, My code will not break when there is a display name change. One of my client was too UI rather than business logic, since the enduser are high profile managers, spacing between columns and readabiltily are first class citizen.  Those changes that we made to the list library did not affect our code and the application was running without code refactoring.

    Backto your question, I will use Internal names in my CAML query to minimize error as follows

    item["internalName"]

    Your question is subjective, I have not seen any best practices on this subject, being said that, if you are looking for best practice and guidance I would suggest you to start here -

    SharePoint 2010 Guidance http://msdn.microsoft.com/en-us/library/ff770300.aspx ( no idea on SP 2013 guidance availablity)

    Go through the code and doc, You will get the design rational behind each choice.


    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you


    Tuesday, March 18, 2014 3:51 PM