04 May 2008

The mysterious CRM Lookup (I)

1. As many of you already know that the CRM lookup field saves the GUID of the related entity. Let's have a deep view of the lookup field. When you create a relationship between two entities, one entity can reference the other entity through a lookup field. However it's not just create one attribute in the database, it means although you can only see one relationship created in CRM interface, there are some invisible attributes for internal/customizer use. Let's see an example, we know that we can reference some values from a lookup fields:


crmForm.all.regardingobjectid.DataValue[0].id; // The GUID of the lookup.
crmForm.all.regardingobjectid.DataValue[0].name; // The text value of the lookup.
crmForm.all.regardingobjectid.DataValue[0].typename; // The entity type name.


But how CRM get those values? Actually when user open a CRM record, those attributes are downloaded from CRM database to the 'containers' which can be seen from entity's customization.xml, it's a complex structure which I don't want to explain in this post. So when you create a relationship between two entities, the CRM system will create more than 2 'containers'(attributes) in the database to keep other information about the lookup field(e.g. id, typename etc).

2. Set the default value for a lookup field, let's take a look at the special lookup field again: regardingobjectid
In many cases, the regardingobjectid is default to Account, but how can we change the default value to Contact?

In the onLoad() event, you can set the default attributes by using setAttribute method which is unsupported by Microsoft, however it's a standard XML DOM method.

Let's see some examples:


crmForm.all.regardingobjectid.setAttribute("lookuptypes", "1,2"); //only show account and contact
crmForm.all.regardingobjectid.setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif :/_imgs/ico_16_2.gif"); //set the icons
crmForm.all.regardingobjectid.setAttribute("defaulttype", "2"); //default to contact

Instead of using setAttribute method, you can also use CRM method directly:

crmForm.all.regardingobjectid.lookuptypes = "1,2";
crmForm.all.regardingobjectid.lookuptypeIcons = "/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif";
crmForm.all.regardingobjectid.defaulttype = "2";



3. If you have a look of the URL when you open a lookup window, you may see how CRM calls a lookup:



/lookupsingle.aspx?class=ActivityRegarding&objecttypes=1,2,3,4&browse=0&ShowNewButton=1&ShowPropButton=1&DefaultType=0

lookupsingle.aspx has some parameters which can be referenced by our developers, those parameters are:

Objecttypes : Entity code, e.g. Objecttypes = "1, 2" //show account and contact
DefaultType : the default lookup entity, e.g. DefaultType = "2" //default to contact
Browse : bool, 0 = show the "Look for" bar; 1 = browse model, hide the "Look for " bar.
ShowNewButton : bool, 0 = hide the "New" button; 1 = show the "New" button.
ShowPropButton : bool, 0 = hide the "Properties" button; 1 = show the "Properties" button.

In an IFRAME or a ISV solution, if you don't want users to see the 'New' Button, you can just set the URL to:
/lookupsingle.aspx?class=ActivityRegarding&objecttypes=1,2,3,4&browse=0&ShowNewButton=0&ShowPropButton=1&DefaultType=0

It's cool so far! But how about if want to hide the 'New' button in CRM?
You can't just say: crmForm.all.regardingobjectid.ShowNewButton = 0; it doesn't work. But what you can do is in the onLoad() event, use attachEvent method to attach a setadditionalparams event for the regardingobjectid. Again, those methods are all unsupported customisations, however, those are widely used in the Web development.

/*
Function: show/hide the 'New' button of lookup
bShow = 0 : hide the New Button
bShow = 1 : show the New Buton
*/
function NewButton(bShow)
{
return function()
{
crmForm.all.regardingobjectid.AddParam("ShowNewButton", bShow);
}
}
crmForm.all.regardingobjectid.attachEvent("setadditionalparams",NewButton(0));

33 comments:

  1. Anonymous11:27 am

    Hi, thanks for this article. The only thing I am not sure about - where to add the addtional JavaScript Code?!

    The Lookup View of a specific entity doesn't have an editable onLoad event ? Or did you mean to just add this snippet to the lookupsingle.aspx to set the default Item to what we want?

    Thanks, yours renew

    ReplyDelete
  2. It's in entity's onLoad() event.

    ReplyDelete
  3. Anonymous10:11 am

    I am using the /_controls/lookup/lookupsingle.aspx from a custom aspx page and a custom 'lookup style' text box server control. It all works fine but i can't seem to make the Remove Value button enabled. Any ideas?

    Thanks

    Ant

    ReplyDelete
  4. Anonymous5:53 pm

    I have tried to add the Campaign entity as a lookuptype to the regarding object of a phone call. It puts it into the list in the lookup dialog, but when I select it gives a crm error dialog and writes nothing the the event log?

    Any Ideas

    ReplyDelete
  5. Anonymous3:50 am

    Looking wow gold for thrilling weapons, wow gold items and new pets? Beating wow gold the more powerful and wow gold 5000 crueler giants? Becoming the cheers of your clanbuy wow gold 5000and impressing your friends? wow gold All in http://www.masswowgold.com, We are the wow gold best alliance of the online wow goldgame players! We have: 24×7 online wow gold support;50,000+ registered users;10,000+ Paypalcheap WOW goldreputations;4 years professional service provider;We get wow gold gold from the players cheap WOW gold who do not need them any more or wow gold 5000 collect them from the direct cheap WOW gold gold farmers with wow gold lower price. Now the sell wow gold WOW gold is under big promotion. sell wow gold Registered Member will get 10% bonus.wow gold 5000 Most of the orders can be completedv sell wow gold in 3 hours. And we will give our customers the extra 5% gold if wow gold 5000 we can not complete the order in cheap WOW gold 24 hours.We deliver cheap WOW gold the gold by sell wow gold face-to-face trade wow gold 5000 in game only. Full refund will be warranted if wow gold 5000 we can not complete the cheap WOW gold orders in cheap WOW gold time.

    ReplyDelete
  6. Anonymous10:07 pm

    酒店經紀PRETTY GIRL 台北酒店經紀人 ,禮服店 酒店兼差PRETTY GIRL酒店公關 酒店小姐 彩色爆米花酒店兼職,酒店工作 彩色爆米花酒店經紀, 酒店上班,酒店工作 PRETTY GIRL酒店喝酒酒店上班 彩色爆米花台北酒店酒店小姐 PRETTY GIRL酒店上班酒店打工PRETTY GIRL酒店打工酒店經紀 彩色爆米花

    ReplyDelete
  7. Anonymous6:29 pm

    I am grateful to you for this great content.aöf thanks radyo dinle cool hikaye very nice ssk sorgulama only cinsellik very nice ehliyet only home free kadın last go korku jomax med olsaoy hikaye lesto go müzik dinle free only film izle love aşk only mp3 indir only radyolar lest go açıköğretim free net only filmler

    ReplyDelete
  8. Hi Jim,

    Its indeed a great article. I would like to know how we could have a regardingobject lookup in a custom entity form. Basically I need to have the same functionality which a Task form has, selecting whatever lookup value.

    Shamira

    ReplyDelete
  9. Anonymous9:04 am

    Your article is very good.I like it very much.
    Once upon a time, there was a mouse father.He wanted to marry his daughter to the greatest person in the world.But, who was the greatest person in the world?Oh!
    puma ferrari shoes
    cheap nike shoesThe sun! He must be the greatest person in the world.The mouse father went to talk to the sun."Hello! Mr. Sun.
    puma shoes
    ferrari shoes
    I know you are the greatest person in the world.Would you marry my daughter?""What? I'm not the greatest person in the world. The greatest person is the cloud.If he comes out, I’ll be covered."
    nike shox nz
    Ugg Boots
    The mouse father went to talk to the cloud. “Hello! Mr. Cloud. I know you are the greatest person in the world. Would you marry my daughter?”
    nike 360 air max
    nike shox shoes
    “What? I’m not the greatest person in the world. The greatest person is the wind.If he comes out, I’ll be blown away.”
    cheap puma shoes
    puma drift cat
    The mouse father went to talk to the wind. “Hello! Mr. Wind. I know you are the greatest person in the world.Would you marry my daughter?” “What? I’m not the greatest person in the world. The greatest person is the wall. If he comes out, I’ll be stopped.”
    cheap nike shox
    nike air max 360
    The mouse father went to talk to the wall. “Hello! Mr. Wall. I know you are the greatest person in the world. Would you marry my daughter?” “What? I’m not the greatest person in the world. The greatest person is YOU, the mouse.” “The greatest person in the world is … mouse?” “Yes, the greatest person in the world is mouse. See? If mouse comes out, I’ll be bit!”
    nike air max
    pumas shoes
    The mouse father was very happy. He finally knew mouse was the greatest person in the world. He would marry his daughter to the handsome mouse next door.
    spot season
    Running in Autumn
    It is time for sporting
    cheap jordan shoes

    ReplyDelete
  10. Thanks for the article.
    But I just want to disable the "Remove Value" button.
    How can I do it?
    thanks

    ReplyDelete
  11. Hi Jim! I like your posts. Im facing a new problem.. I want to aagg a new object types to look up, beside Account, Contact, User and Leads. I wanna add a new Entity I created.. Can I do that? how can I do it?

    Thanks Jim..

    ReplyDelete
  12. Last month, Sonoma Partners and Microsoft had an very useful article for CRM developers: Setting Up Your Development Environment, I have abstract it into Chinese version. In this post, I’d like to give my idea about how to build up a handy Dynamics CRM…
    http://www.refurbishedusedlaptop.ca/

    ReplyDelete
  13. Hello, your blog is really good, I like it very much!By the way, if you like nike shoes you can come here to have a look!
    Three icons converge in Nike Shoes Us, a bold design that combines the best style and cushioning features from legends of Nike Air Max Shoes. With the lacing system of the '95, "Nike air max 2011the silhouette of the '97, and the full-length Max Air inspired by the Nike Air Max 2009, this shoe delivers unbeatable comfort 24 hours a day, seven days a week.

    Nike Air Max 1
    Air Max Griffey 1
    Nike Air Max 180
    Nike Air Max 2009
    Nike Air Max 2010
    Nike Air Max 24 7
    Nike Air Max 87
    Nike Air Max 2011
    Nike Air Max 91
    Nike Air Max BW
    Nike Air Max Plus TN
    Nike Air Max LTD
    Nike Air Max Boots
    Nike Air Max Presto
    Nike Air Max Skyline
    Nike Air Max Turbulence
    Nike Air Max Fitsole
    Nike Air Max Goadome
    Nike Air Max Zenyth
    Nike Air Max Wildwood Supreme
    Nike Air Max Zoom Kobe
    Nike Air Max Shoes.

    ReplyDelete
  14. Christian Louboutin Outlet Online shoe store is up for many years.A man who wants to play its expertise, it must fit the social environment needs. If you need from the social environment, their expertise will lose value. Therefore, we have according to community needs, determine their own actions, better to show themselves. Christian Louboutin Outlet Online shoes wear can make you look more beautiful, more attractive feet.

    ReplyDelete
  15. Anonymous8:30 am

    Nice post! Thanks for sharing!
    Comprare Cialis Generico

    ReplyDelete
  16. Really impressed! Everything is very open and very clear explanation of issues. Your website is very useful. Thanks for sharing. Looking forward to more!
    Anime forums
    Naruto forums
    Manga forums
    Luffy forums
    Bleach forums
    Naruto Shippuden
    Naruto Shippuden forums

    Cheap Web Design Company India
    Web hosting reviews
    Web hosting Tips
    Advertising network reviews

    ReplyDelete
  17. I wanted to thank you for this great read!! I definitely enjoyed every little bit of it, I have you bookmarked to check out all the new stuff you post.I am a china tour lover,You can learn more: travel to Beijing | Guilin Tourist Attractions | What to See in Guilin

    ReplyDelete
  18. I really appreciate spending some time to talk about that, I believe firmly regarding this and so really enjoy understanding more about this kind of subject.This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this. CRM Software || MLM Software in Mumbai || ERP Software || System Software in Mumbai

    ReplyDelete
  19. Anonymous5:18 am


    Thanks for your extraordinary blog. Your idea for this was so brilliant. This would provide people with an excellent tally resource from someone who has experienced such issues. You would be coming at the subject from a different angle and people would appreciate your honesty and frankness. Good luck for your next blog!
    Tally ERP 9 Training
    tally classes
    Tally Training institute in Chennai
    Tally course in Chennai

    ReplyDelete
  20. Thank you very much for the information you shared, it’s all I’ve been looking for. The content is more related.

    Java Training in Chennai

    Java Course in Chennai

    ReplyDelete
  21. Wonderful sharing..thanks a lot for writing this article.

    DevOps Training in Chennai
    DevOps Training in Chennai


    ReplyDelete
  22. Thanks for sharing such a amazing article, it was really useful and I would like to thank you for this article, am very much interested
    to learn new thing like this. Keep posting like this valuable information.
    Data Science Training In Chennai

    Data Science Course In Chennai

    ReplyDelete
  23. Hi I am from Join Pak Navy I and I really like your work thanks for this information and keep it up you are doing good.

    ReplyDelete
  24. Thanks for posting the best information and the blog is very helpful. BEST TRAINING INSTITUTE FOR AWS

    ReplyDelete
  25. https://pfskillbuilders.com/copy-writing-course-kolkata
    Do you want to play with words and set a fun and bright future in the marketing industry? Look no further! Introducing our groundbreaking Copywriting Mastery Course, designed to transform your comments into compelling stories that captivate, convert, and are compelling. Learn copywriting courses in Kolkata from PfSkillBuilders and enable yourself to dominate the copywriting field.

    Join our Copywriting Mastery Course now and receive:
    Instant Access to All Modules
    Downloadable Resources and Cheat Sheets
    Course Completion Certificate
    Access to Our Vibrant Copywriting Community


    PFSkillBuilders provides a fun yet professional learning environment and makes you market ready. So Wait no more and enroll in a copywriting course to earn a six-figure salary!


    ReplyDelete