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
Solved

CRM 2011 Default Lookup Values Not Connecting

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

839 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