简体   繁体   English

Javascript-从MS Dynamics CRM Online添加和检索数据

[英]Javascript - Add and retrieve data from MS Dynamics CRM Online

I want to add/retrieve data from MS Dynamics CRM Online 2011 using pure Javascript. 我想使用纯Javascript从MS Dynamics CRM Online 2011添加/检索数据。 I've searched whole day but could only find to do this with Dynamics SDK, C#, VB or JScript. 我整天都在搜索,但是只能通过Dynamics SDK,C#,VB或JScript来做到这一点。

Is there any way to do this in pure javascript? 有没有办法用纯JavaScript做到这一点? I just need to find a web service to send/ get data to/from but couldn't find it. 我只需要找到一个Web服务即可向/从/发送数据,但找不到它。 Is there any such web service or api exists??? 是否存在任何此类Web服务或API ??? Please help I am totally confused!!! 请帮助我完全困惑!!! Thanks. 谢谢。

If required as mentioned by others you CAN connect using SOAP (probably not recommended but as you want to know). 如果其他人提到需要,则可以使用SOAP进行连接(可能不建议这样做,但是您想知道)。 If you don't know how to use SOAP/JavaScript then I suggest you read this: Simplest SOAP example 如果您不知道如何使用SOAP / JavaScript,那么我建议您阅读以下内容: 最简单的SOAP示例

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. 若要使用Office 365连接到CRM Online(所有Windows Live帐户都将迁移到Office 365),则需要获取安全令牌,然后将其用于您的请求。

The following is a request for tokens in PHP that you should be able to refactor for JavaScript. 以下是对PHP中的令牌的请求,您应该可以对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 根据您的crm区域,根据需要更改Endpoint Reference地址。

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: 如果您使用“ CRM 2011 SOAP”和以下四个函数“ Create”,“ Update”,“ Retrieve”和“ RetrieveMultiple”进行搜索,则应获取许多SOAP示例,例如:

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

The two ways to interact with Javascript and CRM is via either OData, or SOAP services. 与Javascript和CRM交互的两种方式是通过OData或SOAP服务。 The easiest method is to use OData if possible. 如果可能的话,最简单的方法是使用OData。

The problem you're going to run into is Authentication with Odata. 您将遇到的问题是Odata身份验证。 OData Access is not supported outside of CRM javascript and Silverlight . CRM javascript和Silverlight之外不支持OData Access (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) (尽管我使用LinqPad创建了我的Odata查询,并且它可以很好地查询CRM,所以我不确定这是怎么回事)

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. 解决此问题的常用方法是编写自己的Web服务,该服务将对CRM进行身份验证,然后使用SDK检索和更新数据,并以轻松的方式将其公开。

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. 正如Guido指出的那样,您应该能够使用来自Java的SOAP请求,但是我也只能在CRM内完成此操作,而且我不确定您还将遇到什么身份验证问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用纯Javascript从MS Dynamics CRM Online 2015添加/检索数据 - I want to add/retrieve data from MS Dynamics CRM Online 2015 using pure Javascript 从 MS Dynamics CRM 中的 html webresource 窗口传递数据 - Pass data from html webresource window in MS Dynamics CRM 如何在MS Dynamics CRM Online中单击按钮时重定向到任何Web资源? - How to redirect to any webresource on button click in MS Dynamics CRM Online? 获取当前登录到MS Dynamics CRM 2011 Online的用户的ID - Get Id of user currently logged into MS Dynamics CRM 2011 Online 动态 crm 使用 odata 从“类型:Microsoft.Crm.Sdk.Data.Services.EntityReference”中检索 guid - dynamics crm using odata to retrieve a guid from "type: Microsoft.Crm.Sdk.Data.Services.EntityReference" ms crm 2011使用javascript检索报价详细信息 - ms crm 2011 retrieve quote details with javascript MS Dynamics CRM 2013子网格与其添加按钮重叠 - Ms dynamics crm 2013 subgrid overlap with its add button 如何使用JavaScript清除MS Dynamics CRM 4.0中的“查找”字段 - How to clear Lookup field in MS Dynamics CRM 4.0 using JavaScript 在动态 CRM 中从对话框 window 运行 JavaScript - Run JavaScript from Dialog window in dynamics CRM 检索快速查看表单值 - Dynamics CRM JavaScript - Retrieve Quick View Form Value - Dynamics CRM JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM