Question

I want to add/retrieve data from MS Dynamics CRM Online 2011 using pure Javascript. I've searched whole day but could only find to do this with Dynamics SDK, C#, VB or JScript.

Is there any way to do this in pure javascript? I just need to find a web service to send/ get data to/from but couldn't find it. Is there any such web service or api exists??? Please help I am totally confused!!! Thanks.

Was it helpful?

Solution 2

The two ways to interact with Javascript and CRM is via either OData, or SOAP services. The easiest method is to use OData if possible.

The problem you're going to run into is Authentication with Odata. OData Access is not supported outside of CRM javascript and Silverlight. (Although I use LinqPad to create my Odata queries, and it queries CRM with it just fine, so I'm not sure what that's all about)

The common method for getting around this is writing your own Webservice that authenticates to CRM, and then uses the SDK to retrieve and update the data, exposing it to you in a restful manner.

As Guido points out, you should be able to use SOAP requests from Java, but I've only ever done this from within CRM as well, and I'm not sure what authentication issues you will face as well.

OTHER TIPS

If required as mentioned by others you CAN connect using SOAP (probably not recommended but as you want to know). If you don't know how to use SOAP/JavaScript then I suggest you read this: Simplest SOAP example

To connect to CRM Online using Office 365 (all Windows Live accounts are migrating to Office 365) then you need to get security tokens then use that for your requests.

The following is a request for tokens in PHP that you should be able to refactor for JavaScript.

$TokenSOAP = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                              <s:Header>
                                <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
                                <a:MessageID>urn:uuid:%s</a:MessageID>
                                <a:ReplyTo>
                                  <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
                                </a:ReplyTo>
                                <a:To s:mustUnderstand="1">%s</a:To>
                                <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                                  <u:Timestamp u:Id="_0">
                                    <u:Created>%sZ</u:Created>
                                    <u:Expires>%sZ</u:Expires>
                                  </u:Timestamp>
                                  <o:UsernameToken u:Id="uuid-cdb639e6-f9b0-4c01-b454-0fe244de73af-1">
                                    <o:Username>%s</o:Username>
                                    <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">%s</o:Password>
                                  </o:UsernameToken>
                                </o:Security>
                              </s:Header>
                              <s:Body>
                                <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
                                  <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
                                    <a:EndpointReference>
                                      <a:Address>urn:crmapac:dynamics.com</a:Address>
                                    </a:EndpointReference>
                                  </wsp:AppliesTo>
                                  <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
                                </t:RequestSecurityToken>
                              </s:Body>
                            </s:Envelope>';

        $TokenSOAP = sprintf($TokenSOAP, self::gen_uuid(), 'https://login.microsoftonline.com/RST2.srf',  self::getCurrentTime(), self::getNextDayTime(), $username, $password);

Change the Endpoint Reference address as required depending on your crm region

This will return two security tokens and a key identifier.

Then you need to do your add and retrieve. If you google "CRM 2011 SOAP" and the following four functions "Create", "Update", "Retrieve", and "RetrieveMultiple" you should get lots of SOAP samples for example:

http://www.mscrmconsultant.com/2012/07/create-update-delete-record-using.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top