Home

Aug 13, 2010

ShowmodelDialog Opening Multiple CRM records

I was working on Silverlight application. We had a strange requirement, to pass the parent accountId from silverlight and set the same using URL addressable form to contact CRM form. I tried using below code to open account form.

var ob = HtmlPage.Window.Invoke("showModalDialog", "http://localhost/Contoso/sfa/accts/edit.aspx", null, "dialogWidth:800px;dialogHeight:900px");

if(ob != null)
{
    try
  
{
        txtAccountID.Text = ((System.Windows.Browser.ScriptObject)(((System.Windows.Browser.ScriptObject)(((System.Windows.Browser.ScriptObject)ob).GetProperty("items"))).GetProperty("0"))).GetProperty("id").ToString();
        txtAccountName.Text = ((System.Windows.Browser.ScriptObject)(((System.Windows.Browser.ScriptObject)(((System.Windows.Browser.ScriptObject)ob).GetProperty("items"))).GetProperty("0"))).GetProperty("name").ToString();
    }
    catch (Exception ee)
    {
        string sMessage = ee.Message.ToString();
    }
}
It opens the contact form however when I saved contact it opens one more the contact form in edit mode as this is as per the behavior of CRM 4.0 tp display any entity in edit mode after creation.
In Asp.net if we open a window using showmodalDialog then we can avoid opening multiple modal window by setting up <base parent = ‘_self’/>. In order do the same in CRM you can use below code:

var base= document.createElement('base');
base.target= '_self';
document.getElementsByTagName('head')[0].appendChild(base);

I hide the Save & Save and New button in order to display on “Save and Close”  

if (document.all._MBcrmFormSave != undefined)  {   document.all._MBcrmFormSave.style.display='none';}
if(document.all._MBcrmFormSubmitCrmForm59truetruefalse != undefined)  {   document.all._MBcrmFormSubmitCrmForm59truetruefalse.style.display='none';}


Thanks, Amol

No comments: