@@ -39,7 +39,7 @@ Any suggestions are welcome!
3939 * [ Fetch All records] ( #fetch-all-records )
4040 * [ Execute Web API functions] ( #execute-web-api-functions )
4141 * [ Execute Web API actions] ( #execute-web-api-actions )
42- * [ Entity and Attribute Metadata requests examples ] ( #entity-and-attribute- metadata-requests-examples )
42+ * [ Working with Metadata Definitions ] ( #working-with- metadata-definitions )
4343 * [ Create Entity] ( #create-entity )
4444 * [ Retrieve Entity] ( #retrieve-entity )
4545 * [ Update Entity] ( #update-entity )
@@ -54,6 +54,11 @@ Any suggestions are welcome!
5454 * [Delete Relationship](#delete-relationship)
5555 * [Retrieve Relationship](#retrieve-relationship)
5656 * [Retrieve Multiple Relationships](#retrieve-multiple-relationships)
57+ * [Create Global Option Set](#create-global-option-set)
58+ * [Update Global Option Set](#update-global-option-set)
59+ * [Delete Global Option Set](#delete-global-option-set)
60+ * [Retrieve Global Option Set](#retrieve-global-option-set)
61+ * [Retrieve Multiple Global Option Sets](#retrieve-multiple-global-option-sets)
5762* [ Formatted Values and Lookup Properties] ( #formatted-values-and-lookup-properties )
5863* [ Using Alternate Keys] ( #using-alternate-keys )
5964* [ Making requests using Entity Logical Names] ( #making-requests-using-entity-logical-names )
@@ -929,7 +934,7 @@ dynamicsWebApi.executeUnboundAction("WinOpportunity", actionRequest).then(functi
929934});
930935```
931936
932- ## Entity and Attribute Metadata requests examples
937+ ## Working with Metadata Definitions
933938
934939` Version 1.4.3+ `
935940
@@ -1207,6 +1212,78 @@ You can also use common request functions to create, retrieve and update entity
120712125 . During entity or attribute metadata update you can use ` mergeLabels ` property to set ** MSCRM.MergeLabels** attribute. By default ` mergeLabels: false ` .
120812136 . To send entity or attribute definition use ` entity ` property.
12091214
1215+ #### Examples
1216+
1217+ Retrieve entity metadata with attributes (with common properties):
1218+
1219+ ``` js
1220+ var request = {
1221+ collectionName: ' EntityDefinitions' ,
1222+ key: ' 00000000-0000-0000-0000-000000000001' ,
1223+ select: [' LogicalName' , ' SchemaName' ],
1224+ expand: ' Attributes'
1225+ };
1226+
1227+ dynamicsWebApi .retrieveRequest (request).then (function (entityMetadata ){
1228+ var attributes = entityMetadata .Attributes ;
1229+ }).catch (function (error ){
1230+ // catch an error
1231+ });
1232+ ```
1233+
1234+ Retrieve attribute metadata and cast it to the StringType:
1235+
1236+ ``` js
1237+ var request = {
1238+ collectionName: ' EntityDefinitions' ,
1239+ key: ' LogicalName="account"' ,
1240+ navigationProperty: ' Attributes' ,
1241+ navigationPropertyKey: ' LogicalName="firstname"' ,
1242+ metadataAttributeType: ' Microsoft.Dynamics.CRM.StringAttributeMetadata'
1243+ };
1244+
1245+ dynamicsWebApi .retrieveRequest (request).then (function (attributeMetadata ){
1246+ var displayNameDefaultLabel = attributeMetadata .DisplayName .LocalizedLabels [0 ].Label ;
1247+ }).catch (function (error ){
1248+ // catch an error
1249+ });
1250+ ```
1251+
1252+ Update entity metadata with ** MSCRM.MergeLabels** header set to ` true ` :
1253+
1254+ ``` js
1255+ var request = {
1256+ collectionName: ' EntityDefinitions' ,
1257+ key: ' LogicalName="account"'
1258+ };
1259+
1260+ dynamicsWebApi .retrieveRequest (request).then (function (entityMetadata ){
1261+ // 1. change label
1262+ entityMetadata .DisplayName .LocalizedLabels [0 ].Label = ' Organization' ;
1263+ // 2. configure update request
1264+ var updateRequest = {
1265+ collectionName: ' EntityDefinitions' ,
1266+ key: entityMetadata .MetadataId ,
1267+ mergeLabels: true ,
1268+ entity: entityMetadata
1269+ };
1270+ // 3. call update request
1271+ return dynamicsWebApi .updateRequest (updateRequest);
1272+ }).catch (function (error ){
1273+ // catch an error
1274+ });
1275+
1276+ // it is the same as:
1277+ dynamicsWebApi .retrieveEntity (' LogicalName="account"' ).then (function (entityMetadata ){
1278+ // 1. change label
1279+ entityMetadata .DisplayName .LocalizedLabels [0 ].Label = ' Organization' ;
1280+ // 2. call update request
1281+ return dynamicsWebApi .updateEntity (entityMetadata, true );
1282+ }).catch (function (error ){
1283+ // catch an error
1284+ });
1285+ ```
1286+
12101287### Create Relationship
12111288
12121289``` js
@@ -1359,75 +1436,159 @@ dynamicsWebApi.retrieveRelationships(['SchemaName', 'MetadataId'], "ReferencedEn
13591436});
13601437```
13611438
1362- #### Examples
1439+ ### Create Global Option Set
13631440
1364- Retrieve entity metadata with attributes (with common properties):
1441+ ` version 1.4.6+ `
13651442
13661443``` js
1367- var request = {
1368- collectionName: ' EntityDefinitions' ,
1369- key: ' 00000000-0000-0000-0000-000000000001' ,
1370- select: [' LogicalName' , ' SchemaName' ],
1371- expand: ' Attributes'
1444+ var optionSetDefinition = {
1445+ " @odata.type" : " Microsoft.Dynamics.CRM.OptionSetMetadata" ,
1446+ IsCustomOptionSet: true ,
1447+ IsGlobal: true ,
1448+ IsManaged: false ,
1449+ Name: " new_customglobaloptionset" ,
1450+ OptionSetType: " Picklist" ,
1451+ Options: [{
1452+ Value: 0 ,
1453+ Label: {
1454+ LocalizedLabels: [{
1455+ Label: " Label 1" , LanguageCode: 1033
1456+ }],
1457+ UserLocalizedLabel: {
1458+ Label: " Label 1" , LanguageCode: 1033
1459+ }
1460+ },
1461+ Description: {
1462+ LocalizedLabels: [],
1463+ UserLocalizedLabel: null
1464+ }
1465+ }, {
1466+ Value: 1 ,
1467+ Label: {
1468+ LocalizedLabels: [{
1469+ Label: " Label 2" , LanguageCode: 1033
1470+ }],
1471+ UserLocalizedLabel: {
1472+ Label: " Label 2" , LanguageCode: 1033
1473+ }
1474+ },
1475+ Description: {
1476+ LocalizedLabels: [],
1477+ UserLocalizedLabel: null
1478+ }
1479+ }],
1480+ Description: {
1481+ LocalizedLabels: [{
1482+ Label: " Description to the Global Option Set." , LanguageCode: 1033
1483+ }],
1484+ UserLocalizedLabel: {
1485+ Label: " Description to the Global Option Set." , LanguageCode: 1033
1486+ }
1487+ },
1488+ DisplayName: {
1489+ LocalizedLabels: [{
1490+ Label: " Display name to the Custom Global Option Set." , LanguageCode: 1033
1491+ }],
1492+ UserLocalizedLabel: {
1493+ Label: " Display name to the Custom Global Option Set." , LanguageCode: 1033
1494+ }
1495+ },
1496+ IsCustomizable: {
1497+ Value: true , " CanBeChanged" : true , ManagedPropertyLogicalName: " iscustomizable"
1498+ }
13721499};
13731500
1374- dynamicsWebApi .retrieveRequest (request ).then (function ( entityMetadata ) {
1375- var attributes = entityMetadata . Attributes ;
1376- }).catch (function (error ){
1377- // catch an error
1501+ dynamicsWebApi .createGlobalOptionSet (optionSetDefinition ).then (function ( id ) {
1502+ // metadata id
1503+ }).catch (function (error ) {
1504+ // catch error here
13781505});
13791506```
13801507
1381- Retrieve attribute metadata and cast it to the StringType:
1508+ ### Update Global Option Set
1509+
1510+ ` version 1.4.6+ `
1511+
1512+ ** Important!** Publish your changes after update, otherwise a label won't be modified.
13821513
13831514``` js
1384- var request = {
1385- collectionName: ' EntityDefinitions' ,
1386- key: ' LogicalName="account"' ,
1387- navigationProperty: ' Attributes' ,
1388- navigationPropertyKey: ' LogicalName="firstname"' ,
1389- metadataAttributeType: ' Microsoft.Dynamics.CRM.StringAttributeMetadata'
1390- };
1515+ var key = ' 6e133d25-abd1-e811-816e-480fcfeab9c1' ;
1516+ // or
1517+ key = " Name='new_customglobaloptionset'" ;
13911518
1392- dynamicsWebApi .retrieveRequest (request).then (function (attributeMetadata ){
1393- var displayNameDefaultLabel = attributeMetadata .DisplayName .LocalizedLabels [0 ].Label ;
1394- }).catch (function (error ){
1395- // catch an error
1519+ dynamicsWebApi .retrieveGlobalOptionSet (key).then (function (response ) {
1520+ response .DisplayName .LocalizedLabels [0 ].Label = " Updated Display name to the Custom Global Option Set." ;
1521+ return dynamicsWebApi .updateGlobalOptionSet (response);
1522+ }).then (function (response ) {
1523+ // check if it was updated
1524+ }).catch (function (error ) {
1525+ // catch error here
13961526});
13971527```
13981528
1399- Update entity metadata with ** MSCRM.MergeLabels** header set to ` true ` :
1529+ ### Delete Global Option Set
1530+
1531+ ` version 1.4.6+ `
14001532
14011533``` js
1402- var request = {
1403- collectionName: ' EntityDefinitions' ,
1404- key: ' LogicalName="account"'
1405- };
1534+ var key = ' 6e133d25-abd1-e811-816e-480fcfeab9c1' ;
1535+ // or
1536+ key = " Name='new_customglobaloptionset'" ;
14061537
1407- dynamicsWebApi .retrieveRequest (request).then (function (entityMetadata ){
1408- // 1. change label
1409- entityMetadata .DisplayName .LocalizedLabels [0 ].Label = ' Organization' ;
1410- // 2. configure update request
1411- var updateRequest = {
1412- collectionName: ' EntityDefinitions' ,
1413- key: entityMetadata .MetadataId ,
1414- mergeLabels: true ,
1415- entity: entityMetadata
1416- };
1417- // 3. call update request
1418- return dynamicsWebApi .updateRequest (updateRequest);
1419- }).catch (function (error ){
1420- // catch an error
1538+ dynamicsWebApi .deleteGlobalOptionSet (key).then (function (response ) {
1539+ // check if it was deleted
1540+ }).catch (function (error ) {
1541+ // catch error here
14211542});
1543+ ```
14221544
1423- // it is the same as:
1424- dynamicsWebApi .retrieveEntity (' LogicalName="account"' ).then (function (entityMetadata ){
1425- // 1. change label
1426- entityMetadata .DisplayName .LocalizedLabels [0 ].Label = ' Organization' ;
1427- // 2. call update request
1428- return dynamicsWebApi .updateEntity (entityMetadata, true );
1429- }).catch (function (error ){
1430- // catch an error
1545+ ### Retrieve Global Option Set
1546+
1547+ ` version 1.4.6+ `
1548+
1549+ ``` js
1550+ var key = ' 6e133d25-abd1-e811-816e-480fcfeab9c1' ;
1551+ // or
1552+ key = " Name='new_customglobaloptionset'" ;
1553+
1554+ dynamicsWebApi .retrieveGlobalOptionSet (key).then (function (response ) {
1555+ // response.DisplayName.LocalizedLabels[0].Label
1556+ }).catch (function (error ) {
1557+ // catch error here
1558+ });
1559+
1560+ // select specific attributes
1561+ // select specific attributes
1562+ dynamicsWebApi .retrieveGlobalOptionSet (key, null , [' Name' ]).then (function (response ) {
1563+ // response.DisplayName.LocalizedLabels[0].Label
1564+ }).catch (function (error ) {
1565+ // catch error here
1566+ });
1567+
1568+ // Options attribute exists only in OptionSetMetadata, therefore we need to cast to it
1569+ dynamicsWebApi .retrieveGlobalOptionSet (key, ' Microsoft.Dynamics.CRM.OptionSetMetadata' , [' Name' , ' Options' ]).then (function (response ) {
1570+ // response.DisplayName.LocalizedLabels[0].Label
1571+ }).catch (function (error ) {
1572+ // catch error here
1573+ });
1574+ ```
1575+
1576+ ### Retrieve Multiple Global Option Sets
1577+
1578+ ` version 1.4.6+ `
1579+
1580+ ``` js
1581+ dynamicsWebApi .retrieveGlobalOptionSets ().then (function (response ) {
1582+ var optionSet = response .value [0 ]; // first global option set
1583+ }).catch (function (error ) {
1584+ // catch error here
1585+ });
1586+
1587+ // select specific attributes
1588+ dynamicsWebApi .retrieveGlobalOptionSets (' Microsoft.Dynamics.CRM.OptionSetMetadata' , [' Name' , ' Options' ]).then (function (response ) {
1589+ var optionSet = response .value [0 ]; // first global option set
1590+ }).catch (function (error ) {
1591+ // catch error here
14311592});
14321593```
14331594
@@ -1599,7 +1760,7 @@ the config option "formatted" will enable developers to retrieve all information
15991760- [X] Duplicate Detection for Web API v.9. ` Implemented in v.1.3.4 `
16001761- [X] Ability to use entity names instead of collection names. ` Implemented in v.1.4.0 `
16011762- [X] Entity and Attribute Metadata helpers. ` Implemented in v.1.4.3 `
1602- - [ ] Entity Relationships and Global Option Sets helpers.
1763+ - [X ] Entity Relationships and Global Option Sets helpers. ` Implemented in v.1.4.6 `
16031764- [ ] Batch requests.
16041765- [ ] Intellisense for request objects.
16051766
0 commit comments