Solved

CRM 2011 Default Lookup Values Not Connecting

Posted on 2016-08-15
3
50 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now