locked
How to change attribute value in a lookup? RRS feed

  • Question

  •  

    Dear Members,

     

    I am a bit new to CRM customization. I have an issue which is the cause to a lot of hiccups in my customisation. Can anyone tell me how to change the attribute value in a lookup. For Eg In the account section when I select the "parent account" lookup it always selects the "Account name", instead my client wants account number to be appearing in the lookup. Is it possible to change the attribute? The lookup always pulls the primary attribute of the entity. I guess I have to write a onload script to change the attribute of the lookup. Can anyone pls help me with it?

     

    Thanx in advance

     

    Best

    Prince

    Saturday, December 27, 2008 12:02 AM

Answers

  • Hi,


    This type of behavior is by design; a lookup will always show its related entity primary field.
    Here are a few workarounds you can use:


    The simplest workaround is to swap the name attribute with the accountnumber attribute. This is the easiest way to achieve this since you only need to change the labels on the attributes. This might be a bit confusing to the developer since the account number would now be name and the name would be accountnumber.


    The second workaround would be to attach to the account form onchange event and concatenate the accountnumber to the account name. If you choose this workaround I also suggest creating a new attribute to keep the account name without the number e.g. (new_accountnamewithoutnumber)


    Both workarounds are useful when the system has no accounts. Otherwise you need to update all your accounts.


    The third workaround would be to retrieve the accountnumber (ajax) when the form loads and change the lookup attribute text value to the accountnumber. Of course this is just cosmetics. You can also create a new attribute which would act as a container for the account number and show that instead.


    The Fourth workaround is similar to third workaround but uses a plug-in on the account post retrieve event and simply does the same change on the server side.


    Both workarounds need to be backed up with yet another ajax call when the user changes the lookup value.
    The advantages of using these approaches are that you can integrate them into an existing system without a problem.

    This post will help you with the ajax call. http://mscrm4ever.blogspot.com/2008/09/ajax-using-fetch-message.html
    You may also use this unsupported hack http://forums.microsoft.com/Dynamics/ShowPost.aspx?PostID=2904608&SiteID=27


    Another workaround is to use my lookup preview which can be utilized to display the accountnumber anywhere you like.
    http://mscrm4ever.blogspot.com/2008/09/lookup-preview.html


    Hope this puts you on the right track…


    Adi

     


     

     

    Saturday, December 27, 2008 3:27 PM

All replies

  • Nothing so complicated. If you go to customize entities and select Account, you'll see one of the forms and views is the lookup view. If you open this up you can change the attributes which appear on the form and also the ones it uses to 'Find' records.

    Leon Tribe
    Saturday, December 27, 2008 6:56 AM
  • Dear Leon,

    Thanx for your prompt response. Your answer would have been idle if my question was how to change the "lookup view" of accounts entity. If I change the lookup view also the parent account in the account entity will always pull the account name only and you cannot remove the account name from the view since its the primary attribute. Instead I want to display the acct number in the lookup box which is not possible from the "lookup view". Let me re-iterate my quest this time lets take the eg of contacts. In the contacts entity the parent customer lookup will always pull the "account name" in the lookup box instead I want to customise it to pull "account number" or any other attribute for instance from the account's entity which is definetly not possible by altering lookup views as far as I know. I am sure a Jscript has to be written for this I guess. Currently the lookup is pulling the id of the primary attribute of the entity instead if I change the id to the id of the attribute of my choice it should solve the problem.

    Pls let me know if you require further clarifications.

     

    Best

    Prince

    Saturday, December 27, 2008 9:08 AM
  • Hi,


    This type of behavior is by design; a lookup will always show its related entity primary field.
    Here are a few workarounds you can use:


    The simplest workaround is to swap the name attribute with the accountnumber attribute. This is the easiest way to achieve this since you only need to change the labels on the attributes. This might be a bit confusing to the developer since the account number would now be name and the name would be accountnumber.


    The second workaround would be to attach to the account form onchange event and concatenate the accountnumber to the account name. If you choose this workaround I also suggest creating a new attribute to keep the account name without the number e.g. (new_accountnamewithoutnumber)


    Both workarounds are useful when the system has no accounts. Otherwise you need to update all your accounts.


    The third workaround would be to retrieve the accountnumber (ajax) when the form loads and change the lookup attribute text value to the accountnumber. Of course this is just cosmetics. You can also create a new attribute which would act as a container for the account number and show that instead.


    The Fourth workaround is similar to third workaround but uses a plug-in on the account post retrieve event and simply does the same change on the server side.


    Both workarounds need to be backed up with yet another ajax call when the user changes the lookup value.
    The advantages of using these approaches are that you can integrate them into an existing system without a problem.

    This post will help you with the ajax call. http://mscrm4ever.blogspot.com/2008/09/ajax-using-fetch-message.html
    You may also use this unsupported hack http://forums.microsoft.com/Dynamics/ShowPost.aspx?PostID=2904608&SiteID=27


    Another workaround is to use my lookup preview which can be utilized to display the accountnumber anywhere you like.
    http://mscrm4ever.blogspot.com/2008/09/lookup-preview.html


    Hope this puts you on the right track…


    Adi

     


     

     

    Saturday, December 27, 2008 3:27 PM
  • Dear Adi,

     

    Thank you very much for your fantastic solutions. All my issues got solved instantly after going through all your forums.

     

    My last quest to you is that what is "crm attribute column index". And from where can I get it?

     

    " Generally you can retrieve all columns from the lookup grid with this formula

                Lookup.items[0].values[ crm attribute column index ].value"

       

     

    The below mentioned statement is it the procedure?

     

    1.  Open advanced find and then press control + N to open it in a fresh window.

    2.  Construct the fetch for new_classificationlevel2  and run it.

    3.  In the results view enter this js into the address bar.

         Javascript:void( alert( document.getElementsByName("fetchxml")[0].value ))

    4.  Press Enter.

    This will alert your fetch.

    Now focus the alert dialog and press Ctrl A + Ctrl C to copy it.

    Use this fresh validated fetch in your code

     

    Thanx a bunch in advance.

     

    Best

    Prince

    Monday, December 29, 2008 11:26 PM
  •  

    Hi Prince,


    The CRM attribute column index is the column position within the lookup dialog.
    For example: If the account lookup dialog has 3 columns e.g. name , accountnumber , telephone1 (in that order) then name has an index 0 and telephone1 has an index of 2.  Anyway there is a slightly better way of referencing the data returned from the lookup dialog.
    Here is the post which describes it best.
    http://forums.microsoft.com/Dynamics/ShowPost.aspx?PostID=2904608&SiteID=27

    Look at the thread that is marked as answered.


    Adi

    Tuesday, December 30, 2008 12:50 AM
  • Thank you so much Adi... Everything is now crystal clear.

    And thank you for bringing me on track!!

     

    I guess you have solution to all crm issues....Whcih is phenomenal.

     

    Thank you once again

     

    Best

    Prince

    Tuesday, December 30, 2008 2:16 PM