Solved

CRM 2011 Setting Lookup Defaults

Posted on 2016-08-15
6
154 Views
Last Modified: 2016-08-15
I have been able to set a default lookup  value (FreightName)  using the code below but when I try to set a second lookup (ShipName) , it wipes out my first lookup value and I end up with a value in ShipName but nothing in FreightName.  I have tried renaming the lookup elements but this gives me an error.

Please take a look at the code below and let me know what I can do to populate both lookups (actually I have third I need to populate as well)

Thanks

 
function populate(){
var proceedType = Xrm.Page.data.entity.attributes.get("csc_proceedwithquote");
    proceedType.setValue(1);
    Xrm.Page.getAttribute("csc_proceedwithquote").setSubmitMode("always");
    alert("proceedType");
    var proceedStatus = Xrm.Page.data.entity.attributes.get("csc_proceedwithquotestatus");
    proceedStatus.setValue(862430002);
    Xrm.Page.getAttribute("csc_proceedwithquote").setSubmitMode("always");
    alert("proceedStatusstatus");

    alert("Ribbon Editor Sln");

    FreightName();

    ShipName();


}

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 = "Freight Term";                  // 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 = "Shipment Priority";                  // Entity Name Of That Look Up

    Xrm.Page.getAttribute("csc_shipmentpriority").setValue(lookupValue);

}

Open in new window

0
Comment
Question by:apollo7
  • 4
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Rikin Shah earned 500 total points
ID: 41756401
hi,

You have given entity name. you should use the logical name of the entity. it should be like new_entityname
0
 
LVL 1

Author Comment

by:apollo7
ID: 41756411
So, for example I should be doing the following?  (My prefix is csc_)

Instead of:
lookupValue[0].entityType = "Freight Term";                  // Entity Name Of That Look Up

Use:
lookupValue[0].entityType = "csc_freightterm";                  // Entity Name Of That Look Up

Does this look correct?

Thanks
0
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 41756415
yes. correct.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:apollo7
ID: 41756454
When I changed to the code, it leaves both field empty.  The code changes below.  I may be putting the wrong value, e.g. csc_freightterm is the field name on the form.

  
function populate():

FreightName();

ShipName();


}

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

[b]    lookupValue[0].entityType = "csc_freightterm";                  // Entity Name Of That Look Up
[/b]
    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

    [b]lookupValue[0].entityType = "csc_shipmentpriority";                  // Entity Name Of That Look Up
[/b]
    Xrm.Page.getAttribute("csc_shipmentpriority").setValue(lookupValue);

}

Open in new window

0
 
LVL 1

Author Comment

by:apollo7
ID: 41756569
Ok, got the naming correct to populate the field but have a weird problem as far as what is written to the the fields. After the fields are populated, they look like the following and the form cant be saved.

How the lookups are populated by the code
If I use the spyglass to populate the lookups, then they look correct and the form can be saved.

How the lookups as populated by using the normal method
0
 
LVL 1

Author Closing Comment

by:apollo7
ID: 41757046
Thanks I have code setup correctly
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
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