locked
Close a window in ms crm 2011 RRS feed

  • Question

  • Hi

    i opened a window with url using the below javascript  coding.

    window.open(url);

    now i need to close the window using javascript 

    i tried the below coding but not worked

    window.close();

    self.close();

    Xrm.Page.ui.close();

    kindly help me.


    kathiravan sathasivam

    Tuesday, February 12, 2013 6:35 AM

Answers

  • Hi piyush,

    thanks for your quick reply, if you share any sample code for plugin will be good for me.

    thanks 

    kathir


    kathiravan sathasivam

    • Marked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    • Unmarked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    • Marked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    Monday, February 18, 2013 9:58 AM
  • I don't have the working sample ready with me right now to send out sms from plugin but refer the MSDN sample at http://technet.microsoft.com/en-us/library/gg509030.aspx, am sure this will help you.

    Please don't forget to mark the answer, if it helps. Piyush

    • Marked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    Monday, February 18, 2013 10:17 AM

All replies

  • Hi,

    you should be able to do it by just using Xrm.Page.ui.close();

    did you check : http://mahenderpal.wordpress.com/2011/07/01/close-ms-crm-2011-form-using-js/


    Contact Me
    Follow me on Twitter
    My Facebook Page
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Tuesday, February 12, 2013 7:20 AM
    Moderator
  • The only problem you seem to be having is that the close() method is never getting closed, you must have put it in the wrong place.

    Can you elaborate your scenario and where are the scripts placed.


    Please don't forget to mark the answer, if it helps. Piyush

    Tuesday, February 12, 2013 7:20 AM
  • hi piyush,

    thanks for ur reply, here my code.


    function sendsms()
    {

    var mobileno = Xrm.Page.getAttribute("pt_primarymobile").getValue();

    var msg = "Dear " + name +" , Thanks for your enquiry"

    var url = "http://bulksms.com/sendsms?uname=uname&pwd=pwd1&senderid=u1Y&to="+ mobileno +"&msg=" + msg +"&route=T";


    if (mobileno != null)
    {
        window.open(url,"","width=200,height=100");
        Xrm.Page.ui.close();
        alert("SMS Sent");

    }

    }

    script is triggered  in onsave event. 

    thanks

    kathir


    kathiravan sathasivam

    Tuesday, February 12, 2013 7:28 AM
  • It seems that you are taking the wrong route in sending sms using window.open(). I would recommend that you use HTTP GET request for achieving this.

    var httpReq = null;
    function sendSMS() {
    	httpReq = new XMLHTTPREQUEST();
    	httpReq.onreadystatechange = Process;
    	var url = "http://bulksms.com/sendsms?uname=uname&pwd=pwd1&senderid=u1Y&to="+ mobileno +"&msg=" + msg +"&route=T";
    	httpReq.open("GET", url, true);
    	httpReq.send(null);
    }
    
    function Process()
    {
    	if(httpReq.readyState == 4 && httpReq.status == 200)
    	{
    		alert('message sent');
    	}
    	else
    	{
    		alert('There was an error');
    	}
    }

    Hope this helps.


    Please don't forget to mark the answer, if it helps. Piyush

    Tuesday, February 12, 2013 7:56 AM
  • hi piyush,

    thanks for ur post, while using the above code, i am getting error "Access is denied" while reading the line httplReq.open("GET",url,true). with  security role "system administrator"

    kindly guide me.


    kathiravan sathasivam

    Tuesday, February 12, 2013 9:50 AM
  • This is because we are trying to do a Cross-domain scripting to send out the sms. there are two possible ways by which you can make it work.

    1. Send Message logic should go to server-side code (Plug-in or Custom Workflow activity)
    2. If you want to use JavaScript only then you can try going with JSONP, head to http://mscrmshop.blogspot.in/2012/07/crm2011-and-cross-domain-calls-part-1.html for a reference on using JSONP for cross domain calls.
      Note: This is kind of a hack so use it at your own risk.

    Please don't forget to mark the answer, if it helps. Piyush

    Tuesday, February 12, 2013 10:12 AM
  • You can also try going to IE settings and enable cross domain calls, this is really a client side so you'll have to do this on all the clients who are using CRM.

    Enable the setting that says "Access Data Source across domains"


    Please don't forget to mark the answer, if it helps. Piyush

    • Marked as answer by suray kathir Wednesday, February 13, 2013 4:20 AM
    • Unmarked as answer by suray kathir Monday, February 18, 2013 9:46 AM
    Tuesday, February 12, 2013 10:18 AM
  • hi piyush,

    it is working in onpremises CRM DB, but in online CRM 2011 it is not working it shows the error "Access is denied" while reading the line httplReq.open("GET",url,true)i also enable the access data source across domain.

    Any solutions?

    thanks 

    kathir


    kathiravan sathasivam

    Monday, February 18, 2013 9:19 AM
  • Any particular reason why you want to put the logic on client side? I would recommend that you go by sending your sms logic inside of a plugin, that should do the trick for you.

    Try doing one thing, keep a hidden field on form (Checkbox) and in your javascript when you want to send out a sms just set the value of that field to true and trigger a plugin on change of the checkbox you just created.

    Your plugin will contain the logic for sending out a mail. I'm recommending this approach because cross domain calls can be dangerous, doing the same thing from server-side code would definitely reduce this risk.


    Please don't forget to mark the answer, if it helps. Piyush

    Monday, February 18, 2013 9:40 AM
  • Hi piyush,

    thanks for your quick reply, if you share any sample code for plugin will be good for me.

    thanks 

    kathir


    kathiravan sathasivam

    • Marked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    • Unmarked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    • Marked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    Monday, February 18, 2013 9:58 AM
  • I don't have the working sample ready with me right now to send out sms from plugin but refer the MSDN sample at http://technet.microsoft.com/en-us/library/gg509030.aspx, am sure this will help you.

    Please don't forget to mark the answer, if it helps. Piyush

    • Marked as answer by suray kathir Monday, February 18, 2013 1:46 PM
    Monday, February 18, 2013 10:17 AM
  • Hi Piyush,

    thanks for your post, As i created a plugin and it is working fine...thanks for your kind help.

    regards

    kathir


    kathiravan sathasivam

    Monday, February 18, 2013 1:45 PM