简体   繁体   中英

I want to add/retrieve data from MS Dynamics CRM Online 2015 using pure Javascript

I would like to update an entity with some data from another entity in the load through javascript in CRM 2015 is possible?

In CRM 2011 I used the code below:

var xml = '' +
            '<?xml version=\'1.0\' encoding=\'utf-8\'?>' +
            '<soap:Envelope xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\'>' +
            ' <soap:Header>' +
            ' <CrmAuthenticationToken xmlns=\'http://schemas.microsoft.com/crm/2007/WebServices\'>' +
            ' <AuthenticationType xmlns=\'http://schemas.microsoft.com/crm/2007/CoreTypes\'>0</AuthenticationType>' +
            ' <OrganizationName xmlns=\'http://schemas.microsoft.com/crm/2007/CoreTypes\'>OrganizationName </OrganizationName>' +
            ' <CallerId xmlns=\'http://schemas.microsoft.com/crm/2007/CoreTypes\'>00000000-0000-0000-0000-000000000000</CallerId>' +
            ' </CrmAuthenticationToken>' +
            ' </soap:Header>' +
            ' <soap:Body>' +
            ' <RetrieveMultiple xmlns=\'http://schemas.microsoft.com/crm/2007/WebServices\'>' +
            ' <query xmlns:q1=\'http://schemas.microsoft.com/crm/2006/Query\' xsi:type=\'q1:QueryExpression\'>' +
            ' <q1:EntityName></q1:EntityName>' +
            ' <q1:ColumnSet xsi:type=\'q1:ColumnSet\'>' +
            ' <q1:Attributes>' +
            ' <q1:Attribute></q1:Attribute>' +
            ' </q1:Attributes>' +
            ' </q1:ColumnSet>' +
            ' <q1:Distinct>false</q1:Distinct>' +
            ' <q1:Criteria>' +
            ' <q1:FilterOperator>And</q1:FilterOperator>' +
            ' <q1:Conditions>' +
            ' <q1:Condition>' +
            ' <q1:AttributeName>new_estadoid</q1:AttributeName>' +
            '<q1:Operator>Equal</q1:Operator>' +
            '<q1:Values>' +
            '<q1:Value xsi:type=\'xsd:string\'>' + "" + '</q1:Value>' +
            '</q1:Values>' +
            ' </q1:Condition>' +
            ' </q1:Conditions>' +
            ' </q1:Criteria>' +
            ' </query>' +
            ' </RetrieveMultiple>' +
            ' </soap:Body>' +
            '</soap:Envelope>' +
            '';

Have a look at the CRM SDK, it includes a javascript file SDK.REST.js that will allow you to execute your RetrieveMultipleRecords with a simple call.

Recommend you download (Dynamics CRM SDK):

https://msdn.microsoft.com/en-us/library/hh547453.aspx

And this page show you how to use the SDK.REST.js to retrieve records from CRM:

https://msdn.microsoft.com/en-us/library/gg985387.aspx

In short, you can then call the SDK.REST.retrieveMultipleRecords() function and get the data you need from within JavaScript.

Not sure about it, but what you are doing may be a little too complex for this task. You could accomplish this without javascript . I'm working on the same issues on MS CRM 2013 on-premises, and can share you what i've learned, hope it applies to you too.

You can build a workflow (Process: https://technet.microsoft.com/en-us/library/dn531067.aspx ) on the system that gets triggered before a new record is created on the entity that requires the information, adding dynamic values from the source entity to display at the Create Form as it is loaded.

You can relate to this article that explain some of the steps of this solution: https://www.salentica.com/crm-2013-real-time-workflows/

*Is important to note that both entities must be related with a Relationship defined in the system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM