Skip to content

Commit 36f3f16

Browse files
add: functions to retrieve entity and attribute metadata
1 parent 9de0d38 commit 36f3f16

File tree

7 files changed

+1531
-36
lines changed

7 files changed

+1531
-36
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>ShowAllFiles</ProjectView>
29+
<ProjectView>ProjectFiles</ProjectView>
3030
<NodejsPort>1337</NodejsPort>
3131
<StartWebBrowser>True</StartWebBrowser>
3232
</PropertyGroup>

lib/dynamics-web-api-callbacks.js

Lines changed: 202 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function DynamicsWebApi(config) {
211211
var entityUrl = response.headers['OData-EntityId']
212212
? response.headers['OData-EntityId']
213213
: response.headers['odata-entityid'];
214-
var id = /[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(entityUrl)[0];
214+
var id = /([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(entityUrl)[1];
215215
successCallback(id);
216216
}
217217
}
@@ -1128,7 +1128,207 @@ function DynamicsWebApi(config) {
11281128
};
11291129

11301130
_makeRequest('POST', request, 'executeAction', onSuccess, errorCallback);
1131-
}
1131+
};
1132+
1133+
/**
1134+
* Sends an asynchronous request to create an entity definition.
1135+
*
1136+
* @param {string} entityDefinition - Entity Definition.
1137+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1138+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1139+
*/
1140+
this.createEntity = function (entityDefinition, successCallback, errorCallback) {
1141+
1142+
ErrorHelper.parameterCheck(entityDefinition, 'DynamicsWebApi.createEntity', 'entityDefinition');
1143+
1144+
var request = {
1145+
collection: 'EntityDefinitions',
1146+
entity: entityDefinition
1147+
};
1148+
this.createRequest(request, successCallback, errorCallback);
1149+
};
1150+
1151+
/**
1152+
* Sends an asynchronous request to update an entity definition.
1153+
*
1154+
* @param {string} entityDefinition - Entity Definition.
1155+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1156+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1157+
* @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false.
1158+
*/
1159+
this.updateEntity = function (entityDefinition, successCallback, errorCallback, mergeLabels) {
1160+
1161+
ErrorHelper.parameterCheck(entityDefinition, 'DynamicsWebApi.updateEntity', 'entityDefinition');
1162+
ErrorHelper.guidParameterCheck(entityDefinition.MetadataId, 'DynamicsWebApi.updateEntity', 'entityDefinition.MetadataId');
1163+
1164+
var request = {
1165+
collection: 'EntityDefinitions',
1166+
mergeLabels: mergeLabels,
1167+
key: entityDefinition.MetadataId,
1168+
entity: entityDefinition
1169+
};
1170+
this.updateRequest(request, successCallback, errorCallback);
1171+
};
1172+
1173+
/**
1174+
* Sends an asynchronous request to retrieve a specific entity definition.
1175+
*
1176+
* @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName).
1177+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1178+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1179+
* @param {Array} [select] - Use the $select system query option to limit the properties returned.
1180+
* @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned.
1181+
*/
1182+
this.retrieveEntity = function (entityKey, successCallback, errorCallback, select, expand) {
1183+
1184+
ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.retrieveEntity', 'entityKey');
1185+
1186+
var request = {
1187+
collection: 'EntityDefinitions',
1188+
key: entityKey,
1189+
select: select,
1190+
expand: expand
1191+
};
1192+
1193+
this.retrieveRequest(request, successCallback, errorCallback);
1194+
};
1195+
1196+
/**
1197+
* Sends an asynchronous request to retrieve entity definitions.
1198+
*
1199+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1200+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1201+
* @param {Array} [select] - Use the $select system query option to limit the properties returned.
1202+
* @param {string} [filter] - Use the $filter system query option to set criteria for which entity definitions will be returned.
1203+
*/
1204+
this.retrieveEntities = function (successCallback, errorCallback, select, filter) {
1205+
var request = {
1206+
collection: 'EntityDefinitions',
1207+
select: select,
1208+
filter: filter
1209+
};
1210+
1211+
this.retrieveRequest(request, successCallback, errorCallback);
1212+
};
1213+
1214+
/**
1215+
* Sends an asynchronous request to create an attribute.
1216+
*
1217+
* @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName).
1218+
* @param {Object} attributeDefinition - Object that describes the attribute.
1219+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1220+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1221+
*/
1222+
this.createAttribute = function (entityKey, attributeDefinition, successCallback, errorCallback) {
1223+
ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.createAttribute', 'entityKey');
1224+
ErrorHelper.parameterCheck(attributeDefinition, 'DynamicsWebApi.createAttribute', 'attributeDefinition');
1225+
1226+
var request = {
1227+
collection: 'EntityDefinitions',
1228+
key: entityKey,
1229+
entity: attributeDefinition,
1230+
navigationProperty: 'Attributes'
1231+
};
1232+
1233+
this.createRequest(request, successCallback, errorCallback);
1234+
};
1235+
1236+
/**
1237+
* Sends an asynchronous request to update an attribute.
1238+
*
1239+
* @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName).
1240+
* @param {Object} attributeDefinition - Object that describes the attribute.
1241+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1242+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1243+
* @param {string} [attributeType] - Use this parameter to cast the Attribute to a specific type.
1244+
* @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false.
1245+
*/
1246+
this.updateAttribute = function (entityKey, attributeDefinition, successCallback, errorCallback, attributeType, mergeLabels) {
1247+
ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.updateAttribute', 'entityKey');
1248+
ErrorHelper.parameterCheck(attributeDefinition, 'DynamicsWebApi.updateAttribute', 'attributeDefinition');
1249+
ErrorHelper.guidParameterCheck(attributeDefinition.MetadataId, 'DynamicsWebApi.updateAttribute', 'attributeDefinition.MetadataId');
1250+
1251+
if (attributeType) {
1252+
ErrorHelper.stringParameterCheck(attributeType, 'DynamicsWebApi.updateAttribute', 'attributeType');
1253+
}
1254+
1255+
var request = {
1256+
collection: 'EntityDefinitions',
1257+
key: entityKey,
1258+
entity: attributeDefinition,
1259+
navigationProperty: 'Attributes',
1260+
navigationPropertyKey: attributeDefinition.MetadataId,
1261+
mergeLabels: mergeLabels,
1262+
metadataAttributeType: attributeType
1263+
};
1264+
1265+
this.updateRequest(request, successCallback, errorCallback);
1266+
};
1267+
1268+
/**
1269+
* Sends an asynchronous request to retrieve attribute metadata for a specified entity definition.
1270+
*
1271+
* @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName).
1272+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1273+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1274+
* @param {string} [attributeType] - Use this parameter to cast the Attributes to a specific type.
1275+
* @param {Array} [select] - Use the $select system query option to limit the properties returned.
1276+
* @param {string} [filter] - Use the $filter system query option to set criteria for which attribute definitions will be returned.
1277+
* @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned.
1278+
*/
1279+
this.retrieveAttributes = function (entityKey, successCallback, errorCallback, attributeType, select, filter, expand) {
1280+
1281+
ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.retrieveAttributes', 'entityKey');
1282+
1283+
if (attributeType) {
1284+
ErrorHelper.stringParameterCheck(attributeType, 'DynamicsWebApi.retrieveAttributes', 'attributeType');
1285+
}
1286+
1287+
var request = {
1288+
collection: 'EntityDefinitions',
1289+
key: entityKey,
1290+
navigationProperty: 'Attributes',
1291+
select: select,
1292+
filter: filter,
1293+
expand: expand,
1294+
metadataAttributeType: attributeType
1295+
};
1296+
1297+
this.retrieveRequest(request, successCallback, errorCallback);
1298+
};
1299+
1300+
/**
1301+
* Sends an asynchronous request to retrieve a specific attribute metadata for a specified entity definition.
1302+
*
1303+
* @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName).
1304+
* @param {string} attributeKey - The Attribute Metadata id.
1305+
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
1306+
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
1307+
* @param {string} [attributeType] - Use this parameter to cast the Attribute to a specific type.
1308+
* @param {Array} [select] - Use the $select system query option to limit the properties returned.
1309+
* @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned.
1310+
*/
1311+
this.retrieveAttribute = function (entityKey, attributeKey, successCallback, errorCallback, attributeType, select, expand) {
1312+
1313+
ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.retrieveAttribute', 'entityKey');
1314+
ErrorHelper.keyParameterCheck(attributeKey, 'DynamicsWebApi.retrieveAttribute', 'attributeKey');
1315+
1316+
if (attributeType) {
1317+
ErrorHelper.stringParameterCheck(attributeType, 'DynamicsWebApi.retrieveAttribute', 'attributeType');
1318+
}
1319+
1320+
var request = {
1321+
collection: 'EntityDefinitions',
1322+
key: entityKey,
1323+
navigationProperty: 'Attributes',
1324+
select: select,
1325+
expand: expand,
1326+
metadataAttributeType: attributeType,
1327+
navigationPropertyKey: attributeKey
1328+
};
1329+
1330+
this.retrieveRequest(request, successCallback, errorCallback);
1331+
};
11321332

11331333
/**
11341334
* Creates a new instance of DynamicsWebApi

0 commit comments

Comments
 (0)