Solved

CRM 2011 Default Lookup Values Not Connecting

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

717 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