Answered by:
CRM 2011: Overwrite onclick event

Question
-
Hi,
I would like to overwrite onclick event for a lookup field in order to provide an advanced selection window...
I can attach an event to the control but the standard lookup window still opens...
Is there any way to cancel the standard window opening?
Thank you
My blog : http://mscrmtools.blogspot.com
All my tools for Dynamics CRM 4.0 on my dedicated site: MSCRMTools Repository
Upgraded tools for Dynamics CRM 2011!
View Layout Replicator for Microsoft Dynamics CRM 2011
Searchable Property Updater for Microsoft Dynamics CRM 2011
Ribbon Browser for Microsoft Dynamics CRM 2011Monday, June 20, 2011 3:38 PMModerator
Answers
-
This must be a tough one when you start asking questions. :)
I don't think there is a supported way to do this from within the application. I think you would have to build your own custom web app that functions as a lookup and it would be exposed as an iframe on the crm form. It would interact with CRM using cross-frame scripting and .NET web services.
Jamie Miley
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Proposed as answer by Jamie MileyModerator Monday, June 20, 2011 3:59 PM
- Unproposed as answer by Tanguy T [MVP CRM]MVP, Moderator Tuesday, June 21, 2011 8:18 AM
- Proposed as answer by Jamie MileyModerator Wednesday, June 22, 2011 8:48 PM
- Marked as answer by Tanguy T [MVP CRM]MVP, Moderator Monday, July 4, 2011 1:12 PM
Monday, June 20, 2011 3:59 PMModerator
All replies
-
This must be a tough one when you start asking questions. :)
I don't think there is a supported way to do this from within the application. I think you would have to build your own custom web app that functions as a lookup and it would be exposed as an iframe on the crm form. It would interact with CRM using cross-frame scripting and .NET web services.
Jamie Miley
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Proposed as answer by Jamie MileyModerator Monday, June 20, 2011 3:59 PM
- Unproposed as answer by Tanguy T [MVP CRM]MVP, Moderator Tuesday, June 21, 2011 8:18 AM
- Proposed as answer by Jamie MileyModerator Wednesday, June 22, 2011 8:48 PM
- Marked as answer by Tanguy T [MVP CRM]MVP, Moderator Monday, July 4, 2011 1:12 PM
Monday, June 20, 2011 3:59 PMModerator -
Hi Tanguy,
It might help if you post some of your code. I wonder what approach you used to overwrite the onclick event.
Daniel Cai | http://danielcai.blogspot.comTuesday, June 21, 2011 4:58 AM -
Hi guys!
Thanks for helping me.
My problem is not the custom lookup web app, this part works like a charm if I call it from a ribbon button for example.
What I want is to change the behavior of the lookup image to force it launching my web app instead of the standard lookup selection form...
What I already tried:
This is working but the CRM still launches the standard lookup form, since the behavior is coded in a HTC file.window.document.getElementById('parentaccountid').onclick = "window.open(...)";
I also tried to create a new HTC file which is identical to the standard one, but without the onclick event attachement. Then I change the behavior in the form onload
window.document.getElementById('parentaccountid').style.behavior = '...'; // Here I passed the url to my custom HTC file
This time, only my web app is launched but when I want to write in the lookup value using the Xrm sdk, I get the following kind of error message: "object doesn't support method or property 'IsPermissibleType'"
I have a last option I didn't try yet: hiding the image lookup and inserting a custom one with only my behavior... Don't know if it will work...
My blog : http://mscrmtools.blogspot.com
All my tools for Dynamics CRM 4.0 on my dedicated site: MSCRMTools Repository
Upgraded tools for Dynamics CRM 2011!
View Layout Replicator for Microsoft Dynamics CRM 2011
Searchable Property Updater for Microsoft Dynamics CRM 2011
Ribbon Browser for Microsoft Dynamics CRM 2011Tuesday, June 21, 2011 8:18 AMModerator -
Hmm, I tried the onclick approach, and wasn't lucky either.
In this case, I think you might need to think of a different path. You can add another button to the CRM form, but hide the current lookup image button. So you have full control over what happens when the new custom button is clicked while not losing the CRM lookup field on the form which is actually needed when saving the record.
Daniel Cai | http://danielcai.blogspot.comTuesday, June 21, 2011 1:36 PM -
I don't think you will find a supported way to do this without the method I proposed above.
Jamie Miley
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Wednesday, June 22, 2011 8:49 PMModerator -
I suspect you will find it to work if you hide the out of box image and insert your own as you mentioned already. We have done similar things using jquery to retrieve data and replace lookup elements with dropdowns and the key was to hide the existing elements and use your own custom elements (of course making sure that you then write back to the appropriate UI elements after an item is chosen).
Wednesday, June 22, 2011 9:22 PM -
Replacing the image is not working... the image added is not clickable...
I think Jamie's answer is the only one possible...
My blog : http://mscrmtools.blogspot.com
All my tools for Dynamics CRM 4.0 on my dedicated site: MSCRMTools Repository
Upgraded tools for Dynamics CRM 2011!
View Layout Replicator for Microsoft Dynamics CRM 2011
Searchable Property Updater for Microsoft Dynamics CRM 2011
Ribbon Browser for Microsoft Dynamics CRM 2011
SiteMap Editor for Microsoft Dynamics CRM 2011
JavaScript Web Resource Manager for Microsoft Dynamics CRM 2011Monday, July 4, 2011 1:12 PMModerator -
Hi, I have a related question I am hoping you can answer. How do I programmatically pop the lookup window of a lookup field - i.e. fire the click event. I have added a ribbon button to CRM, I want the click of the button to result in the lookup window relating to a specific lookup field on the form to pop.
cheers,
Gareth.
Gareth Tucker +61 406 1234 72Tuesday, September 6, 2011 6:19 AM -
window.document.getElementById('lookup_field').click();Wednesday, October 5, 2011 11:14 PM
-
check this blog post, I think it answer your question, you should override 'onshowdialog' event of lookupfield.
http://mscrmtools.blogspot.fr/2011/07/crm-2011-overriding-lookup-onclick.html
- Edited by saeid64 Saturday, June 30, 2012 1:30 PM
Saturday, June 30, 2012 1:28 PM -
Thanks saeid64... you know, this blog... it is my blog so it seems it is the solution :)
My blog : http://mscrmtools.blogspot.com
Did you try the new CrmDiagTool for Microsoft Dynamics CRM 2011 ? If not, follow me
Upgraded tools for Dynamics CRM 2011!
View Layout Replicator | Searchable Property Updater | Ribbon Browser | SiteMap Editor | JavaScript Web Resource Manager | Role updaterMonday, July 2, 2012 9:45 AMModerator