web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JQuery / Javascript Rest Data Operation Samples - Getting started

(0) ShareShare
ReportReport
Posted on by 140

Dear all,

I am new to CRM data connections so I have been doing some research, trying samples and snippets online however I have decided to start from the beginning instead of hacking up the samples. I hope you can help me get up and running with a javascript rest samples available from the CRM SDK to do a simple create opertaion to CRM Online.

For both Jquery and Javascript samples, the first message I received was 'Context is not available' called by the context function. What I started to do was edit the web config file to enter the crm connection string, straight from the example provided:

 <connectionStrings>
    <add name="Server=CRM Online, organization=mycompany, user=myusername" connectionString="Url=https://mycompany.crm4.dynamics.com; Username=myemail; Password=mypassword;"/>
  </connectionStrings>

Following that, I explicitly instantiated the crmconnection and context variables under the context function:

CrmConnection connection = new CrmConnection("CRM");
//CrmConnection connection = CrmConnection.Parse("Url=http://mycompany.crm4.dynamics.com; Username=myusername; Password=mypassword;");
//var connection = "Url=http://mycompany.crm4.dynamics.com; Username=myusername; Password=mypassword;";
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);

The result was more undefined messages or 'expected ;' messages. If I used CrmConnection, I receive the error expected semicolon, if I used var connection I receive organisation service is undefined.

I started adding references to use the Crmconnection class and the organisationservicecontext class such as Microsoft.Xrm.Sdk, Microsoft.Xrm.Client and many others.

Still, lots of undefined and expected ; messages. From this point I started hacking up the code until it didn't even look like the sample anymore. E.g. removing the service variable, getting a readystate of 0, etc.

So back to the start, can anyone help with the initial 'expected ;' error using the crmconnection ?

I would really appreciate it, and it is valentines day after all.

Regards,

Steph

*This post is locked for comments

I have the same question (0)
  • StephNicolaou Profile Picture
    140 on at

    Hi Guido,

    Thank you for your response. The sample code that I am trying to use can be found at:

    msdn.microsoft.com/.../gg334427.aspx .

    If I cannot instantiate a CRM connection or include the XML within the web config file for the Javascript / JQuery methods, please can you constructively inform me how I would integrate my CRM connection string using the Javascript or JQuery methods?

    Regards,

    Steph

  • Verified answer
    jlattimer Profile Picture
    24,562 on at

    The short answer is that a writing JavaScript code against Dynamics CRM is meant to be done from within Dynamics CRM. This would some in the form of some scripting attached to a form event or a web resource that contains some HTML along with the script - again at this point you are already authenticated. If you are looking to connect to Dynamics CRM from an external web application  using JavaScript you would need to have a proxy application (with a server to server connection like the SDK examples) in between to talk to as CRM does not allows Cross-Origin Resource Sharing and the browser blocks any responses (thinking immediately when trying to authenticate). This is a limitation of the modern browser not any code that has or has not been written. On the happenstance you are looking to connect externally from a mobile application using JavaScript you can take a look at this example application I put together. Since it doesn't use a standard browser it bypasses the CORS restrictions and allows communication - this is also using SOAP based communication to authenticate and process requests. 

  • StephNicolaou Profile Picture
    140 on at

    Hi Jason,

    Thanks for your response, it confirmed a lot for me. I am indeed trying to connect from an external source and thought those guides were for that purpose. My aim was to create a simple form on a website to create a contact and send those details to the CRM. I have managed to connect to the CRM using C# with the organization service proxy and create an account using the Entity object.

    Update:

    I have now successfully created an aspx form which parses the values into the create account method in the code behind aspx.cs file. Would you say that this was the best way to go about it?

    Update:

    In addition, I would like to also learn about using the CRM forms which can link to websites described by AdxStudio. I am also following a new method shown on AdxStudio and MSDN however these guides don't fill in the gaps, for example, following the MSDN example exactly results in errors, but I am still working on these. If you have a better guide on using a CRM form, it would be much appreciated.

    Kind regards,

    Steph

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans