CRM 2011 – How to set up a lookup using Javascript

I haven’t had to use this javascript yet but I know I am going to need in the future, so I am going to blog about it so I can find it.

there are quite a few examples of this but this blog post compares it to CRM 4 as well, which is extra useful.

CRM 4

var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].typename = typeValue;

crmForm.all.fieldName.DataValue = value;

CRM 2011

var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].entityType = typeValue;

Xrm.Page.getAttribute(“fieldName”).setValue(value);

How about doing it on one line like this instead.

CRM 4
crmForm.all.field.DataValue = [{id: idValue, name: textValue, typename: typeValue}];

CRM 2011
Xrm.Page.getAttribute(“fieldName”).setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

if you want some more examples and a discussion this forum discussion is the place to look

This page also had an interesting link to an article

Seven JavaScript Things I Wish I Knew Much Earlier In My Career

which I found interesting because I know very little about Javascript

About these ads

15 thoughts on “CRM 2011 – How to set up a lookup using Javascript

  1. Metaphorix September 21, 2011 / 2:29 am

    it’s very difficult to compare javascript from CRM 4 and CRM 2011. My advice is just to learn how it works in CRM 2011 and get using it. You will find it better in the long run once you have learned how to use it.

  2. manmis April 20, 2012 / 3:13 am

    Short!

    Xrm.Page.getAttribute(“fieldName”).setValue([new {id: idValue, name: textValue, entityType: typeValue}]);

  3. titus June 18, 2012 / 12:52 pm

    can i know how to set range to price list to a product in sales navigation

  4. villerantala June 13, 2013 / 4:59 pm

    Hi, Can you help me please?

    “value[0].id = idValue;
    value[0].name = textValue;
    value[0].entityType = typeValue;”

    I didn’t get this part, id = i have to put the guid of the record?
    name = i have to put the name of what? entity? record?
    type = the user? systemuser? the entity :l

    I’m nuts and newbbie in this javascript for CRM…

    Thanks for the help.

    • aaa June 27, 2014 / 2:57 pm

      id = the guid of the record
      name = the text you usualy see in the lookup – (its the primary field of the record)
      entityType = the logical name of the entity (like – account or contact …)

  5. salah September 5, 2013 / 11:05 am

    thnx…it worked

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s