Javascript reads/writes SQL DB. SOAP? REST? Something else?

Answered Javascript reads/writes SQL DB. SOAP? REST? Something else?

  • Monday, May 07, 2012 8:23 PM
     
     

    Hello,

    Trying to find the best way to accomplish this.  We will be adding an item in CRM that will display in each contact entity.  We want it to be a separate page, so I'm thinking use an IFrame.  Basically when a new contact is created the person making that contact will have the ability to choose yes/no for a selection box that will create the contact in our custom customer portal.  I could do this easily with an aspx page and C# in the back but I was told that can not be done in CRM.  So my plan is create an html page with javascript that will insert the information into our sql database.  We also need to have the ability to have a choice box that displays available security groups, so it will also need to read from SQL as well.  

    If I am wrong in any of my assumptions please tell me, or if you know of a better way please let me know.  I have only used Soap a few time but nothing really like this, I looked up REST and it does not seem so bad.  I just need help figuring out the best way to attack this. 

All Replies

  • Monday, May 07, 2012 10:13 PM
     
     
    I've written a few custom html pages as webresources and it's a fantastic way to build customizations. As for SQL requests you would likely need a custom web service.
  • Tuesday, May 08, 2012 12:54 AM
     
     
    That was my thought but how would I use a webservice to populate items on the page?  I need to show all the security groups so that we can choose what security group to put them in.  I would normally just hard code this but with new customers coming in we will have different security groups all the time.
  • Tuesday, May 08, 2012 5:15 AM
    Moderator
     
     

    Why do you need to read from SQL ? If you're reading from the CRM database, then you can used a Fetch query via the CRM web services, and avoid the need for SQL access. If, however, you're reading data from a different database, and need SQL, then you could use the SQL Server SQLXML feature, or build an ASP .Net page to do this.

    Note that MS do support use of ASP .Net, but only if deployed outside of the CRM web site


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk


  • Tuesday, May 08, 2012 11:47 AM
     
     

    I would like to do this through ASP and an IFrame, but my only issue then is how do I pass the contact name through the IFrame?

    Workflow:

    1. Open Contact
    2. Click the "Add Access" button in the left hand Navigation
    3. Displayed page shows if user already has access, what security groups they belong too, and security groups they don't belong too (I can get this info through some select queries)

    My issue is:

    How do I pass the contacts info into the IFrame and in turn into the ASP form?

    As for the SQLXML I have never used it I'll take a look.

  • Tuesday, May 08, 2012 7:59 PM
    Moderator
     
     Answered
    In Crm 2011, the only supported way to deploy an ASP .Net application is outside of the CRM web site. This means that the only way to pass the contact information is on the querystring, which can be done by passing contextual information

    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk


  • Wednesday, May 09, 2012 3:50 PM
     
     

    Ok so just want to be sure about how this is done.  In CRM I make my link connect to external resource with the parameters like this: http://<server>:82/custom_aspx/default.aspx? typename=contact

    (Its on port 82 because I read you have to make an entirely different website for aspx and CRM to work)

    Then in my code I have: 

            protected void Page_Load(object sender, EventArgs e)
            {
                NameValueCollection nc;
                string name;
                nc = Request.QueryString;
                name = nc.ToString();
                lbl.Text = name;
            }

    on the aspx page there is a label(id=lbl) and I want that to display what is being passed through.  Just as a test.  Am I doing this right?

  • Wednesday, May 09, 2012 8:47 PM
     
     Answered

    I got it to work great!! Using the contextual information was great! I never knew that thank you so much!!

    I made this web resource in CRM:

     

    HTML><HEAD>
    <SCRIPT type=text/javascript>
    function load()
    {
    var mail = window.parent.Xrm.Page.getAttribute("emailaddress1").getValue();
    var address = "Http://<server>/CRM_portalUsers/Default.aspx?"+mail;

      ifrm = document.createElement("IFRAME"); 
       ifrm.setAttribute("src",address); 
       ifrm.style.width = 640+"px"; 
       ifrm.style.height = 480+"px"; 
       document.body.appendChild(ifrm); 
    }
    </SCRIPT>

    <META charset=utf-8></HEAD>
    <BODY onload=load(); contentEditable=true></BODY></HTML>

    And on the aspx page there is the simple label I mentioned before with this code behind it.

            protected void Page_Load(object sender, EventArgs e)
            {
                NameValueCollection nc;
                string name;
                nc = Request.QueryString;
                name = nc.ToString();
                lbl.Text = name;
            }

    I then made a left hand Nav item in contacts pointing to the web resource.  Everytime the left hand nav item is clicked it opens an iframe with the aspx page, and the contacts email is displayed where the label is.  This works great now I can use that email address to query the outside database and get the information we want!!

    Thanks again for all the help!!! 

    • Marked As Answer by Billyj82 Wednesday, May 09, 2012 8:47 PM
    •