Get OData option set values and names - odata

I am using odata api, now I have an attribute on an entity that is an option select like :
attribute name is : status
values are: 1, 2, 3
names: done, progress, new
the thing is when I am using postman to fetch metadata and all I get for the fields 'status' its that its type integer.
Question how do I fetchj option names and values from metadata so I get values and names in response ?
Currently I get this:
<Property Name="status" Type="Edm.Int32">
<Annotation Term="Org.OData.Core.V1.Description" String="" />
</Property>
But I want to get the value and names on response ?

This could be vastly simplified, assuming all you want are the int values, and names for a particular option set attribute of an entity:
GET [Organization URI]/api/data/v8.2/EntityDefinitions(LogicalName='contact')/Attributes(LogicalName='status')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)
The $select=LogicalName is just so it doesn't return all the other metadata for the attribute, and the $expand=OptionSet($select=Options) is for local option sets, and the GlobalOptionSet($select=Options) is for Global. If you know what type it is, you can skip it the other, but if you are putting this logic in a shared library (you are aren't you?) then adding both won't hurt:
{
"#odata.context":"http://YourOrg.com/YourInstance/api/data/v8.2/$metadata#EntityDefinitions('new_entity')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata(LogicalName,OptionSet,GlobalOptionSet,OptionSet(Options),GlobalOptionSet(Options))/$entity",
"LogicalName":"new_familyshortname",
"MetadataId":"dc11c01f-b6bd-4664-82d0-3a521841c1f5",
"OptionSet#odata.context":"http://YourOrg.com/YourInstance/api/data/v8.2/$metadata#EntityDefinitions('new_entity')/Attributes(dc11c01f-b6bd-4664-82d0-3a521841c1f5)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata/OptionSet(Options)/$entity",
"OptionSet":null,
"GlobalOptionSet":{
"#odata.type":"#Microsoft.Dynamics.CRM.OptionSetMetadata",
"Options":[
{
"Value":117280000,
"Label":{
"LocalizedLabels":[
{
"Label":"English Value 1",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3cb6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
},
{
"Label":"French Value 1",
"LanguageCode":1036,
"IsManaged":false,
"MetadataId":"d88be67d-4a7d-e411-8890-0050569f1654",
"HasChanged":null
}
],
"UserLocalizedLabel":{
"Label":"English Value 1",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3cb6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
}
},
"Description":{
"LocalizedLabels":[
{
"Label":"",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3db6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
}
],
"UserLocalizedLabel":{
"Label":"",
"LanguageCode":1033,
"IsManaged":true,
"MetadataId":"3db6bbd5-796f-e111-8cf3-3cd92b023782",
"HasChanged":null
}
},
"Color":null,
"IsManaged":true,
"MetadataId":null,
"HasChanged":null
},
... MORE ...
],
"MetadataId":"dcbbe460-bedb-4985-9a17-2f3dbc637594"
}
}

According to this article this is a multi-step process.
Please note that all the examples use HTTP GET.
First retrieve the entity's MetaData Id (for this example we're using the entity 'account'):
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=LogicalName,MetadataId&$filter=LogicalName eq 'account'
Returns:
{
"#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(LogicalName,MetadataId)",
"value": [{
"LogicalName": "account",
"MetadataId": "70816501-edb9-4740-a16c-6a5efbc05d84"
}]
}
Then retrieve the attribute's MetaDataId (in this example we're using the option set 'customertypecode'):
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)?$select=LogicalName&$expand=Attributes($select=LogicalName;$filter=LogicalName eq 'customertypecode')
Returns:
{
"#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(LogicalName,Attributes(LogicalName))/$entity",
"LogicalName": "account",
"MetadataId": "70816501-edb9-4740-a16c-6a5efbc05d84",
"Attributes#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(LogicalName)",
"Attributes": [{
"#odata.type": "#Microsoft.Dynamics.CRM.PicklistAttributeMetadata",
"LogicalName": "customertypecode",
"MetadataId": "4e33af09-ba43-4365-a747-c7e4f9992172"
}]
}
Then query with the entity's and attribute's MetadataIds to get the option set values:
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet
Returns (truncated at 2 values):
{
"#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata(LogicalName,OptionSet)/$entity",
"LogicalName": "customertypecode",
"MetadataId": "4e33af09-ba43-4365-a747-c7e4f9992172",
"OptionSet#odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata/OptionSet/$entity",
"OptionSet": {
"MetadataId": "3629e642-b895-41ab-8f1d-ea5bfa30e992",
"HasChanged": null,
"IsCustomOptionSet": false,
"IsGlobal": false,
"IsManaged": true,
"Name": "account_customertypecode",
"ExternalTypeName": null,
"OptionSetType": "Picklist",
"IntroducedVersion": "5.0.0.0",
"Description": {
"LocalizedLabels": [{
"Label": "Type of the account.",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "73f68e38-c78d-48a5-80cb-bee895baab2b",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Type of the account.",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "73f68e38-c78d-48a5-80cb-bee895baab2b",
"HasChanged": null
}
},
"DisplayName": {
"LocalizedLabels": [{
"Label": "Relationship Type",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "e5d47366-fd09-41e6-96a1-cbfdd113b932",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Relationship Type",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "e5d47366-fd09-41e6-96a1-cbfdd113b932",
"HasChanged": null
}
},
"IsCustomizable": {
"Value": true,
"CanBeChanged": false,
"ManagedPropertyLogicalName": "iscustomizable"
},
"Options": [{
"Value": 1,
"Color": null,
"IsManaged": true,
"ExternalValue": null,
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [{
"Label": "Competitor",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6c54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Competitor",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6c54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [],
"UserLocalizedLabel": null
}
},
{
"Value": 2,
"Color": null,
"IsManaged": true,
"ExternalValue": null,
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [{
"Label": "Consultant",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6e54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}],
"UserLocalizedLabel": {
"Label": "Consultant",
"LanguageCode": 1033,
"IsManaged": true,
"MetadataId": "6e54c2fa-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [],
"UserLocalizedLabel": null
}
}
}
}

Related

Get /me/events/{id} returns incorrect calendar object

I tried to fetch list of events from /me/events?$expand=calendar endpoint
and it returns correct calendar object in response.
However, when I tried to fetch one particular event, I received a different calendar.
API used: /me/events/{id}?$expand=calendar
The user has 4 calendars (verified using /me/calendars).
And the calendar id received from /me/events/{id}?$expand=calendar doesn't match with any of them.
Edit
Below are responses for more clarification
End point to list all calendars
https://graph.microsoft.com/v1.0/me/calendars
Response:
{
"value": [
{
"id": "<CALENDAR_ID_1>",
"name": "Calendar",
"color": "auto",
"changeKey": "<changeKey>",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"owner": {
"name": "<Name>",
"address": "<Email>"
}
},
{
"id": "<CALENDAR_ID_2>",
"name": "Birthdays",
"color": "auto",
"changeKey": "<changeKey>",
"canShare": false,
"canViewPrivateItems": true,
"canEdit": false,
"owner": {
"name": "TestVoIP 1",
"address": "<Email>"
}
},
....
]
}
List all events
https://graph.microsoft.com/v1.0/me/events?$expand=calendar
Response:
{
"value": [
{
"id": "<EVENT_ID_1>",
... some other properties
"calendar": {
"id": "<CALENDAR_ID_1>", // Note that this is the calendar id for EVENT_ID_1
"name": "Calendar",
"color": "auto",
"changeKey": "<changeKey>",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"owner": {
"name": "<Name>",
"address": "<Email>"
}
},
},
{
"id": "<EVENT_ID_2>",
... some other properties
"calendar": {
"id": "<CALENDAR_ID_1>",
"name": "Calendar",
"color": "auto",
"changeKey": "<changeKey>",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"owner": {
"name": "<Name>",
"address": "<Email>"
}
},
},
...
]
}
Get event with ID
https://graph.microsoft.com/v1.0/me/events/<EVENT_ID_1>?$expand=calendar
Response:
{
"id": "<EVENT_ID_1>",
... some other properties
"calendar": {
"id": "<DIFFERENT_CALENDAR_ID>", // Note that this is entirely different calendar id than we noted in list of events response AND its not available in list of calendars response too
"name": null,
"color": "auto",
"changeKey": null,
"canShare": false,
"canViewPrivateItems": false,
"canEdit": false,
"owner": null
}
}

Expanding singleValueExtendedProperty not working when retrieving Event details

I am trying to retrieve custom property value for an event using Microsoft Graph.
The custom property was created by an Outlook Office.js Add-ing
Here is request
/v1.0/me/events/{id}?$expand=singleValueExtendedProperties($filter=id eq 'String {00020329-0000-0000-C000-000000000046} Name myCusProp')
This returns a successful response from Graph but it does not return the singleValueExtendedProperty. The Outlook add-in, however, is still able to retrieve the property value from the same Event.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('{id}')/events/$entity",
"#odata.etag": "W/\"SdXmMkSN8kCNtzTsQ4x1lwAD7sMWVg==\"",
"id": "{id}",
"createdDateTime": "2019-09-30T10:12:34.110571Z",
"lastModifiedDateTime": "2019-09-30T10:23:57.8338159Z",
"changeKey": "SdXmMkSN8kCNtzTsQ4x1lwAD7sMWVg==",
"categories": [],
"originalStartTimeZone": "blah blah",
"originalEndTimeZone": "blah blah Standard Time",
"iCalUId": "040000008...EBBE4999DC5A61D31AC544",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "WWW-002",
"bodyPreview": "rt",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.office365.com/owa/?itemid=AQMkADU2OWFjYTFjLWNkMGYtNDdlNS1hNDIxLWIxYjlmY...DqyJu%2FWyzJk6m5v0MbSs7lwcASdXmMkSN8kCNtzTsQ4x1lwAAAgENA...AD7q52owAAAA%3D%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"recurrence": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\n<div>rt</div>\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2019-09-19T02:30:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2019-09-19T03:00:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "",
"locationType": "default",
"uniqueIdType": "unknown",
"address": {},
"coordinates": {}
},
"locations": [],
"attendees": [],
"organizer": {
"emailAddress": {
"name": "Info a",
"address": "name#domain.com"
}
}
}
----Update 1 - office.js code-----
This is office-js/outlook-add-in code reference above.
The custom property value can be read here without an issue.
const item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync(asyncResult => {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
let customProps = asyncResult.value;
customProps.set("myCusProp", "google.com");
customProps.saveAsync(asyncResult => {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
item.loadCustomPropertiesAsync(asyncResult => {
const customProps = asyncResult.value;
const myCusProp = customProps.get("myCusProp");
})
}
});
}
});
From documentation:
id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-<add-in id from manifest>'
Instead of myCusProp use cecp-/* add-in id from manifest */
Add-in id is the guid from manifest, this response has a custom properties as JSON.

Can't create ad group

Campaign:
{
"id": "1709932214",
"name": "Noah Baumbach",
"status": "ENABLED",
"servingStatus": "PENDING",
"startDate": "20190219",
"endDate": "20190220",
"budget": {
"budgetId": "1730787529",
"name": "Dominic Schumm",
"amount": {
"ComparableValue.Type": "Money",
"microAmount": "10000"
},
"deliveryMethod": "STANDARD",
"referenceCount": 5,
"isExplicitlyShared": true,
"status": "ENABLED"
},
"conversionOptimizerEligibility": {
"eligible": false,
"rejectionReasons": [
"CONVERSION_TRACKING_NOT_ENABLED"
]
},
"adServingOptimizationStatus": "OPTIMIZE",
"frequencyCap": {
"impressions": "100",
"timeUnit": "DAY",
"level": "CAMPAIGN"
},
"settings": [
{
"attributes": {
"xsi:type": "GeoTargetTypeSetting"
},
"Setting.Type": "GeoTargetTypeSetting",
"positiveGeoTargetType": "DONT_CARE",
"negativeGeoTargetType": "DONT_CARE"
}
],
"advertisingChannelType": "DISPLAY",
"networkSetting": {
"targetGoogleSearch": false,
"targetSearchNetwork": false,
"targetContentNetwork": true,
"targetPartnerSearchNetwork": false
},
"biddingStrategyConfiguration": {
"biddingStrategyType": "MANUAL_CPC"
},
"campaignTrialType": "BASE",
"baseCampaignId": "1709932214"
}
When I try to create ad group with below parameters:
{
campaignId: 1709932214,
name: 'Jess Hegmann',
status: 'ENABLED',
criterionTypeGroup: 'VERTICAL',
targetAll: false,
bidAmount: 10000,
biddingStrategyType: 'MANUAL_CPC',
biddingStrategyName: 'biddingName 123',
adGroupType: 'DISPLAY_STANDARD',
adGroupAdRotationMode: 'OPTIMIZE',
};
Google adwords give me an error:
Failed: "[OperationAccessDenied.OPERATION_NOT_PERMITTED_FOR_CAMPAIGN_TYPE # operations[0].operand.biddingStrategyConfiguration.biddingStrategyType; trigger:'DISPLAY']"
How can I solve this?
I think this might be the reason:
Starting with v201705, this field cannot be set at the ad group or ad group criterion level to any value other than BiddingStrategyType.NONE.
Bid Strategy AdGroup Google Ads

Getting Javascript Grails Jstree

im trying to get jstree to work with
The first step I took was I added the following to the buildconfig.groovy
plugins{
compile "org.grails.plugins:js-tree:0.3.1"
}
Then I created my gsp and added the following to it to test it out which I got from the following jsfiddle
<html>
<head>
<g:javascript library="jquery" plugin="jquery"/>
<jsTree:resources />
</head>
<body>
<div>
<input class="search-input form-control">
</div>
<div id="jstree">
</div>
<script>
$(function() {
$(".search-input").keyup(function() {
var searchString = $(this).val();
console.log(searchString);
$('#jstree').jstree('search', searchString);
});
$('#jstree').jstree({
'core': {
'data': [{
"id": "1.0",
"text": "Fresh Products",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": [{
"id": "2.06.0",
"text": "Ethnic & Specialty",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": false,
"liAttributes": null,
"aAttributes": null
}, {
"id": "2.07.0",
"text": "Natural & Organic",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": false,
"liAttributes": null,
"aAttributes": null
}, {
"id": "2.08.0",
"text": "Prepared Foods",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": false,
"liAttributes": null,
"aAttributes": null
}, {
"id": "2.09.0",
"text": "Seafood",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": false,
"liAttributes": null,
"aAttributes": null
}, {
"id": "2.010.0",
"text": "Seafood",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": false,
"liAttributes": null,
"aAttributes": null
}],
"liAttributes": null,
"aAttributes": null
}, {
"id": "2.0",
"text": "Frozen Products",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": [],
"liAttributes": null,
"aAttributes": null
}, {
"id": "3.0",
"text": "Store Equipment ",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": [],
"liAttributes": null,
"aAttributes": null
}, {
"id": "4.0",
"text": "Packaged Grocery",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": [],
"liAttributes": null,
"aAttributes": null
}, {
"id": "5.0",
"text": "Retail Technology",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": [],
"liAttributes": null,
"aAttributes": null
}, {
"id": "6.0",
"text": "HBC/Non-Foods",
"icon": "",
"state": {
"opened": false,
"disabled": false,
"selected": false
},
"children": [],
"liAttributes": null,
"aAttributes": null
}]
},
"search": {
"case_insensitive": true,
"show_only_matches" : true
},
"plugins": ["search"]
});
});
</script>
</body>
</html>
All that comes up when I run it is a blank search box and text saying "running"
Im not sure what is going wrong, it doesnt seem to be finding the js

Render json to Grails domain list object

If there is one record in request.json the below code works
class BookController {
def save = {
def book = new Book(JSON.parse(yourJson))
book.save(flush:true)
}
}
But how to get bookList if there is multiple records in my request.JSON like:
[{
"id": 3,
"name": "MYNAME",
"description": "test",
"category": 1,
"venue": null,
"status": "Published",
"deleted": false,
"pricingPolicy": null
}, {
"id": 6,
"name": "YZ",
"description": "test6",
"category": 2,
"venue": null,
"status": "Unpublished",
"deleted": false,
"pricingPolicy": null
}, {
"id": 9,
"name": "YZ",
"description": "test6",
"category": 1,
"venue": null,
"status": "Published",
"deleted": false,
"pricingPolicy": null
}]
request.JSON.each{ new Book( it ).save() }
should do

Resources