?
Solved

CRM 2011 Default Lookup Values Not Connecting

Posted on 2016-08-15
3
Medium Priority
?
71 Views
Last Modified: 2016-08-16
I have created some javascript code to write default values to two lookups.  The correct values appear in the lookup field but do not bind to the lookup.  

The values are in the center of the lookup field and stop the form from being saved until the lookup is correctly populated using the spyglass.  

See the examples below.  The first image shows the lookups populated by JavaScript.  The second shows the lookups populated by selecting from the lookup icon.

Lookups populated by javascript
Lookups  populated by using lookup search icon
I will include the javascript below
0
Comment
Question by:apollo7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 1

Author Comment

by:apollo7
ID: 41757096
The javascript that I have been using is below.  I have tried a number of variations but all produce the behavior listed above.

function FreightName() {
    var lookupValue = new Array();
    lookupValue[0] = new Object();
    lookupValue[0].id = "16F711C2-5C9C-E411-8DC3-005056897092";   // Guid Of That Look Up
    lookupValue[0].name = "Collect";                              // Name  Of That Look Up
    lookupValue[0].entityType = "csc_freightterm";                  // Entity Name Of That Look Up
    Xrm.Page.getAttribute("csc_freightterm").setValue(lookupValue);

}

function ShipName() {
    var lookupValue = new Array();
    lookupValue[0] = new Object();
    lookupValue[0].id = "1EF711C2-5C9C-E411-8DC3-005056897092";  // Guid Of That Look Up
    lookupValue[0].name = "Standard Priority";                   // Name  Of That Look Up
    lookupValue[0].entityType = "csc_shipmentpriority";                  // Entity Name Of That Look Up
    Xrm.Page.getAttribute("csc_shipmentpriority").setValue(lookupValue);
}

Open in new window

0
 
LVL 1

Author Comment

by:apollo7
ID: 41757894
I am trying another function that I have used before.  I am still getting the indented value in the lookup (shown above)

function FreightName()
{
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = '{16F711C2-5C9C-E411-8DC3-005056897092}';
lookupItem.typename = 'csc_lookup';
lookupItem.name = 'Collect';
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
Xrm.Page.getAttribute("csc_freightterm").setValue(lookupData);

}

Open in new window

0
 
LVL 1

Accepted Solution

by:
apollo7 earned 0 total points
ID: 41758044
I resolved this myself.  The solution is below:

function FreightName()
{
//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = '{16F711C2-5C9C-E411-8DC3-005056897092}';
lookupItem.typename = 'csc_lookupitem';
lookupItem.name = 'Collect';
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
Xrm.Page.getAttribute("csc_freightterm").setValue(lookupData);

}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question