1
votes

I'm trying to write a javascript to change the default entity in the lookup window for the 'from' field to use the Contact entity. Right now Account is the default entity.

So this is what I have:

document.getElementById("from").setAttribute("defaulttype", "2");
var ViewGUID= "a2d479c5-53e3-4c69-addd-802327e67a0d";
Xrm.Page.getControl("from").setDefaultView(ViewGUID);

I got the code actually from this website on point #34: http://garethtuckercrm.com/2011/03/16/jscript-reference-for-microsoft-dynamics-crm-2011/

I attached the function into the form and publish the solution however it's still showing Account as the default entity.

Any idea is appreciated. Thanks.

2
What version of CRM do you use?Andrew Butenko

2 Answers

1
votes

Try this code (for CRM 2011)

    document.getElementById("from").setAttribute("defaulttype", "2");
    document.getElementById("from").setAttribute("lookuptypenames", "contact:2:Contact");
    document.getElementById("from").setAttribute("lookuptypes", "2");

And add this in case you want to disable the view picker after appliying your viewID

    document.getElementById("from").setAttribute("disableViewPicker", "1");

Realised now you have not specified the CRM version well, this code should work in CRM 2013

    document.getElementById("from_i").setAttribute("defaulttype", "2");
    document.getElementById("from_i").setAttribute("lookuptypenames", "contact:2:Contact");
    document.getElementById("from_i").setAttribute("lookuptypes", "2");
-1
votes

You need to do this with jquery:

$("#" + "from").attr("defaulttype", "2");

or

document.getElementById("from").attr("defaulttype", "2");

Remember this is not supported code.