Skip to content

Commit db5d414

Browse files
Added wiki
1 parent 20eb3db commit db5d414

File tree

5 files changed

+4370
-111
lines changed

5 files changed

+4370
-111
lines changed

DynamicsWebApi.njsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<OutputPath>.</OutputPath>
2727
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
2828
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
29-
<ProjectView>ProjectFiles</ProjectView>
29+
<ProjectView>ShowAllFiles</ProjectView>
3030
<NodejsPort>1337</NodejsPort>
3131
<StartWebBrowser>True</StartWebBrowser>
3232
</PropertyGroup>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
DynamicsWebApi is a Microsoft Dynamics CRM Web API helper library written in JavaScript.
77
It is compatible with: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online.
88

9+
Please check [DynamicsWebApi Wiki](/wiki/) where you will find documentation to DynamicsWebApi API and more.
10+
911
Libraries for browsers can be found in [dist](/dist/) folder.
1012

1113
Any suggestions are welcome!

lib/dynamics-web-api-callbacks.js

Lines changed: 96 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,21 @@ var dwaRequest = function () {
8484
*/
8585

8686
/**
87-
* DynamicsWebApi - a Microsoft Dynamics CRM Web API helper library. Current version uses Promises instead of Callbacks.
88-
*
87+
* Constructor.
88+
* @constructor
8989
* @param {DWAConfig} [config] - configuration object
90+
* @example
91+
//Empty constructor (will work only inside CRM/D365)
92+
*var dynamicsWebApi = new DynamicsWebApi();
93+
* @example
94+
//Constructor with a configuration parameter (only for CRM/D365)
95+
*var dynamicsWebApi = new DynamicsWebApi({ webApiVersion: '9.0' });
96+
* @example
97+
//Constructor with a configuration parameter for CRM/D365 and Node.js
98+
*var dynamicsWebApi = new DynamicsWebApi({
99+
* webApiUrl: 'https:/myorg.api.crm.dynamics.com/api/data/v9.0/',
100+
* includeAnnotations: 'OData.Community.Display.V1.FormattedValue'
101+
*});
90102
*/
91103
function DynamicsWebApi(config) {
92104

@@ -108,6 +120,8 @@ function DynamicsWebApi(config) {
108120
* Sets the configuration parameters for DynamicsWebApi helper.
109121
*
110122
* @param {DWAConfig} config - configuration object
123+
* @example
124+
dynamicsWebApi.setConfig({ webApiVersion: '9.0' });
111125
*/
112126
this.setConfig = function (config) {
113127

@@ -155,15 +169,6 @@ function DynamicsWebApi(config) {
155169

156170
this.setConfig(config);
157171

158-
/**
159-
* Makes a request to web api
160-
*
161-
* @param {string} method - Method of the request.
162-
* @param {DWARequest} request - Request to Web Api
163-
* @param {string} [functionName] - Indictes the name of the function that called make request.
164-
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
165-
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
166-
*/
167172
var _makeRequest = function (method, request, functionName, successCallback, errorCallback) {
168173
Request.makeRequest(method, request, functionName, _internalConfig, successCallback, errorCallback);
169174
};
@@ -177,6 +182,17 @@ function DynamicsWebApi(config) {
177182
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
178183
* @param {string|Array} [prefer] - Sets a Prefer header value. For example: ['retrun=representation', 'odata.include-annotations="*"'].
179184
* @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned.
185+
* @example
186+
*var lead = {
187+
* subject: "Test WebAPI",
188+
* firstname: "Test",
189+
* lastname: "WebAPI",
190+
* jobtitle: "Title"
191+
*};
192+
*
193+
*dynamicsWebApi.create(lead, "leads", function (id) {
194+
*}, function (error) {
195+
*});
180196
*/
181197
this.create = function (object, collection, successCallback, errorCallback, prefer, select) {
182198

@@ -663,14 +679,6 @@ function DynamicsWebApi(config) {
663679
}, successCallback, errorCallback);
664680
}
665681

666-
/**
667-
* Sends an asynchronous request to retrieve records.
668-
*
669-
* @param {DWARequest} request - An object that represents all possible options for a current request.
670-
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
671-
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
672-
* @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions.
673-
*/
674682
var retrieveMultipleRequest = function (request, successCallback, errorCallback, nextPageLink) {
675683

676684
ErrorHelper.callbackParameterCheck(successCallback, "DynamicsWebApi.retrieveMultiple", "successCallback");
@@ -695,6 +703,14 @@ function DynamicsWebApi(config) {
695703
_makeRequest('GET', request, 'retrieveMultiple', onSuccess, errorCallback);
696704
}
697705

706+
/**
707+
* Sends an asynchronous request to retrieve records.
708+
*
709+
* @param {DWARequest} request - An object that represents all possible options for a current request.
710+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
711+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
712+
* @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions.
713+
*/
698714
this.retrieveMultipleRequest = retrieveMultipleRequest;
699715

700716
var _retrieveAllRequest = function (request, successCallback, errorCallback, nextPageLink, records) {
@@ -726,18 +742,6 @@ function DynamicsWebApi(config) {
726742
_retrieveAllRequest(request, successCallback, errorCallback);
727743
}
728744

729-
/**
730-
* Sends an asynchronous request to count records. Returns: DWA.Types.FetchXmlResponse
731-
*
732-
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
733-
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
734-
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
735-
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
736-
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
737-
* @param {number} [pageNumber] - Page number.
738-
* @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null.
739-
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
740-
*/
741745
var executeFetchXml = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) {
742746

743747
ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.executeFetchXml", "collection");
@@ -778,7 +782,33 @@ function DynamicsWebApi(config) {
778782
_makeRequest('GET', request, 'executeFetchXml', onSuccess, errorCallback);
779783
}
780784

781-
this.fetch = this.executeFetchXml = executeFetchXml;
785+
/**
786+
* Sends an asynchronous request to count records. Returns: DWA.Types.FetchXmlResponse
787+
*
788+
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
789+
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
790+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
791+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
792+
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
793+
* @param {number} [pageNumber] - Page number.
794+
* @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null.
795+
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
796+
*/
797+
this.fetch = executeFetchXml;
798+
799+
/**
800+
* Sends an asynchronous request to count records. Returns: DWA.Types.FetchXmlResponse
801+
*
802+
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
803+
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
804+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
805+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
806+
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
807+
* @param {number} [pageNumber] - Page number.
808+
* @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null.
809+
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
810+
*/
811+
this.executeFetchXml = executeFetchXml;
782812

783813
var _executeFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records) {
784814
var records = records || [];
@@ -797,6 +827,10 @@ function DynamicsWebApi(config) {
797827
executeFetchXml(collection, fetchXml, internalSuccessCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId);
798828
}
799829

830+
var innerExecuteFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, impersonateUserId) {
831+
return _executeFetchXmlAll(collection, fetchXml, successCallback, errorCallback, includeAnnotations, null, null, impersonateUserId);
832+
}
833+
800834
/**
801835
* Sends an asynchronous request to execute FetchXml to retrieve all records.
802836
*
@@ -807,9 +841,19 @@ function DynamicsWebApi(config) {
807841
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
808842
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
809843
*/
810-
this.fetchAll = this.executeFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, impersonateUserId) {
811-
return _executeFetchXmlAll(collection, fetchXml, successCallback, errorCallback, includeAnnotations, null, null, impersonateUserId);
812-
}
844+
this.fetchAll = innerExecuteFetchXmlAll;
845+
846+
/**
847+
* Sends an asynchronous request to execute FetchXml to retrieve all records.
848+
*
849+
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
850+
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
851+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
852+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
853+
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
854+
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
855+
*/
856+
this.executeFetchXmlAll = innerExecuteFetchXmlAll;
813857

814858
/**
815859
* Associate for a collection-valued navigation property. (1:N or N:N)
@@ -979,17 +1023,6 @@ function DynamicsWebApi(config) {
9791023
return _executeFunction(functionName, parameters, collection, id, successCallback, errorCallback, impersonateUserId);
9801024
}
9811025

982-
/**
983-
* Executes a function
984-
*
985-
* @param {string} id - A String representing the GUID value for the record.
986-
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
987-
* @param {string} functionName - The name of the function.
988-
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
989-
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
990-
* @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }.
991-
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
992-
*/
9931026
var _executeFunction = function (functionName, parameters, collection, id, successCallback, errorCallback, impersonateUserId, isUnbound) {
9941027

9951028
ErrorHelper.stringParameterCheck(functionName, "DynamicsWebApi.executeFunction", "functionName");
@@ -1023,7 +1056,6 @@ function DynamicsWebApi(config) {
10231056
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
10241057
*/
10251058
this.executeUnboundAction = function (actionName, requestObject, successCallback, errorCallback, impersonateUserId) {
1026-
10271059
return _executeAction(actionName, requestObject, null, null, successCallback, errorCallback, impersonateUserId, true);
10281060
}
10291061

@@ -1042,17 +1074,6 @@ function DynamicsWebApi(config) {
10421074
return _executeAction(actionName, requestObject, collection, id, successCallback, errorCallback, impersonateUserId);
10431075
}
10441076

1045-
/**
1046-
* Executes a Web API action
1047-
*
1048-
* @param {string} [id] - A String representing the GUID value for the record.
1049-
* @param {string} [collection] - The name of the Entity Collection or Entity Logical name.
1050-
* @param {string} actionName - The name of the Web API action.
1051-
* @param {Object} requestObject - Action request body object.
1052-
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1053-
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1054-
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
1055-
*/
10561077
var _executeAction = function (actionName, requestObject, collection, id, successCallback, errorCallback, impersonateUserId, isUnbound) {
10571078

10581079
ErrorHelper.stringParameterCheck(actionName, "DynamicsWebApi.executeAction", "actionName");
@@ -1093,8 +1114,25 @@ function DynamicsWebApi(config) {
10931114
}
10941115
};
10951116

1117+
/**
1118+
* DynamicsWebApi Utility helper class
1119+
* @typicalname dynamicsWebApi.utility
1120+
*/
10961121
DynamicsWebApi.prototype.utility = {
1122+
/**
1123+
* Searches for a collection name by provided entity name in a cached entity metadata.
1124+
* The returned collection name can be null.
1125+
*
1126+
* @param {string} entityName - entity name
1127+
* @returns {string} a collection name
1128+
*/
10971129
getCollectionName: Request.getCollectionName
10981130
};
10991131

1132+
/**
1133+
* Microsoft Dynamics CRM Web API helper library written in JavaScript.
1134+
* It is compatible with: Dynamics 365 (online), Dynamics 365 (on-premise), Dynamics CRM 2016, Dynamics CRM Online.
1135+
* @module dynamics-web-api
1136+
* @typicalname dynamicsWebApi
1137+
*/
11001138
module.exports = DynamicsWebApi;

0 commit comments

Comments
 (0)