Answered by:
add entity to a lookup crm 2011

Question
-
Hello! I want to add an entity "account" to a "Recipient" field on the task form. Recipient field contains "contact" now.Can anyone please help how to acheive this functionalityWednesday, May 8, 2013 10:09 AM
Answers
-
Hi Fareeha,
To achieve the above you have to create 3 hidden fields
new_lookuptype - to save lookup type
new_lookupid - to save lookup guid
new_lookupname - to save lookup name.
Next write 3 jscript function
//function to handle OnLoad event on task form. function recipientOnLoad() { var constLookupImage = '/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif'; var constLookupNames = 'account:1:Account,contact:2:Contact'; var constLookupType = '1,2'; var savedId = Xrm.Page.getAttribute("new_lookupid").getValue(); var savedType = Xrm.Page.getAttribute("new_lookuptype").getValue(); var savedName = Xrm.Page.getAttribute("new_lookupname").getValue(); var savedEntityName = savedType == "1" ? "account" : "contact"; //checking if the saved name is contact/account document.getElementById("new_recipient").setAttribute("lookuptypes", constLookupType); //Setting the lookup type document.getElementById("new_recipient").setAttribute("lookuptypenames", constLookupNames); //Setting the lookup name document.getElementById("new_recipient").setAttribute("lookuptypeIcons", constLookupImage); //Setting the lookup icon document.getElementById("new_recipient").setAttribute("defaulttype", "2"); // default type - Account entity var recipient = Xrm.Page.getAttribute("new_recipient").getValue(); //If no value is present in the main lookup if (IsNull(recipient) && !IsNull(savedId)) { var value = new Array(); value[0] = new Object(); value[0].displayClass = "ms-crm-Lookup-Item"; value[0].keyValues = new Object(); value[0].values = new Object(); value[0].onclick = "openlui()"; value[0].id = savedId; value[0].entityType = savedEntityName; value[0].typename = savedEntityName; value[0].name = savedName; value[0].type = savedType; Xrm.Page.getAttribute("new_recipient").setValue(value); } } //function to handle OnChange event on lookup. function recipientOnChange() { var recipient = Xrm.Page.getAttribute("new_recipient").getValue(); if (IsNull(recipient) || recipient[0].type == "2") { // Lookup is null or there is a Lead, need to clear hidden fields. To clear one of them will be enough, we will be check this field during onload. Xrm.Page.getAttribute("new_lookupid").setValue(null); } else { // Lookup contains Contact or User, so need to store lookup properties to our hidden fields. Xrm.Page.getAttribute("new_lookuptype").setValue(recipient[0].type); Xrm.Page.getAttribute("new_lookupid").setValue(recipient[0].id); Xrm.Page.getAttribute("new_lookupname").setValue(recipient[0].name); } } //function to handle OnSave event on task form. function recipientOnSave() { var recipient = Xrm.Page.getAttribute("new_recipient").getValue(); if (!IsNull(recipient) && recipient[0].type != '2') { Xrm.Page.getAttribute("new_recipient").setValue(null); } }
Try the above and let us know your views.
Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Edited by Crm.Abhi Wednesday, May 8, 2013 10:30 AM
- Proposed as answer by Crm.Abhi Wednesday, May 8, 2013 10:41 AM
- Marked as answer by Fareeha CH Wednesday, May 8, 2013 11:09 AM
Wednesday, May 8, 2013 10:29 AM
All replies
-
Hi,
Try this link ,it may help you,
http://mscrm2011kt.blogspot.in/2012/04/mscrm-2011-lookup-multi-value-selection.html
http://mscrmgoodies.blogspot.in/2012/02/custom-lookup-in-crm-2011.html
VidhyaM
Wednesday, May 8, 2013 10:16 AM -
Hi Fareeha,
To achieve the above you have to create 3 hidden fields
new_lookuptype - to save lookup type
new_lookupid - to save lookup guid
new_lookupname - to save lookup name.
Next write 3 jscript function
//function to handle OnLoad event on task form. function recipientOnLoad() { var constLookupImage = '/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif'; var constLookupNames = 'account:1:Account,contact:2:Contact'; var constLookupType = '1,2'; var savedId = Xrm.Page.getAttribute("new_lookupid").getValue(); var savedType = Xrm.Page.getAttribute("new_lookuptype").getValue(); var savedName = Xrm.Page.getAttribute("new_lookupname").getValue(); var savedEntityName = savedType == "1" ? "account" : "contact"; //checking if the saved name is contact/account document.getElementById("new_recipient").setAttribute("lookuptypes", constLookupType); //Setting the lookup type document.getElementById("new_recipient").setAttribute("lookuptypenames", constLookupNames); //Setting the lookup name document.getElementById("new_recipient").setAttribute("lookuptypeIcons", constLookupImage); //Setting the lookup icon document.getElementById("new_recipient").setAttribute("defaulttype", "2"); // default type - Account entity var recipient = Xrm.Page.getAttribute("new_recipient").getValue(); //If no value is present in the main lookup if (IsNull(recipient) && !IsNull(savedId)) { var value = new Array(); value[0] = new Object(); value[0].displayClass = "ms-crm-Lookup-Item"; value[0].keyValues = new Object(); value[0].values = new Object(); value[0].onclick = "openlui()"; value[0].id = savedId; value[0].entityType = savedEntityName; value[0].typename = savedEntityName; value[0].name = savedName; value[0].type = savedType; Xrm.Page.getAttribute("new_recipient").setValue(value); } } //function to handle OnChange event on lookup. function recipientOnChange() { var recipient = Xrm.Page.getAttribute("new_recipient").getValue(); if (IsNull(recipient) || recipient[0].type == "2") { // Lookup is null or there is a Lead, need to clear hidden fields. To clear one of them will be enough, we will be check this field during onload. Xrm.Page.getAttribute("new_lookupid").setValue(null); } else { // Lookup contains Contact or User, so need to store lookup properties to our hidden fields. Xrm.Page.getAttribute("new_lookuptype").setValue(recipient[0].type); Xrm.Page.getAttribute("new_lookupid").setValue(recipient[0].id); Xrm.Page.getAttribute("new_lookupname").setValue(recipient[0].name); } } //function to handle OnSave event on task form. function recipientOnSave() { var recipient = Xrm.Page.getAttribute("new_recipient").getValue(); if (!IsNull(recipient) && recipient[0].type != '2') { Xrm.Page.getAttribute("new_recipient").setValue(null); } }
Try the above and let us know your views.
Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Edited by Crm.Abhi Wednesday, May 8, 2013 10:30 AM
- Proposed as answer by Crm.Abhi Wednesday, May 8, 2013 10:41 AM
- Marked as answer by Fareeha CH Wednesday, May 8, 2013 11:09 AM
Wednesday, May 8, 2013 10:29 AM -
Thank you so much Crm.Abhi !! I used your code and modified it according to my fields name and it is working perfectly fine. Thanks a lot :)Wednesday, May 8, 2013 11:09 AM
-
Welcome! :)
Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Wednesday, May 8, 2013 11:25 AM