Hi,
From the msdyn_searchresourceavailability OOB Action, based on the input parameters, i'm trying to retrieve the timeslots. I'm passing preferred resources has an input on the ResourceSpecification input but in the result timeslots i'm getting slots for all the bookable resources. Below is the code which i used in console application, please help me here why the preferred resource is not being considered?
OrganizationRequest resourceAvailabilityReq = new OrganizationRequest("msdyn_searchresourceavailability");
// Requirement
Entity newReqObject = new Entity("msdyn_resourcerequirement");
// newReqObject["msdyn_resourcerequirementid"] = new Guid("3d5b2040-3cbc-ea11-a812-000d3a239e28");
newReqObject["msdyn_fromdate"] = new DateTime(2020, 11, 27, 8, 30, 0, DateTimeKind.Local).ToUniversalTime();
newReqObject["msdyn_todate"] = new DateTime(2020, 11, 30, 17, 30, 0, DateTimeKind.Local).ToUniversalTime();
//newReqObject["msdyn_remainingduration"] = 120;
//newReqObject["msdyn_duration"] = 120;
// Settings organization systemuser
Entity travelRadius = new Entity("travelradius");
travelRadius["Value"] = 99999;
travelRadius["Unit"] = 192350001;
Entity settings = new Entity("organization");
settings["MaxResourceTravelRadius"] = travelRadius;
settings["ConsiderTravelTime"] = false;
settings["UseRealTimeResourceLocation"] = true;
settings["ConsiderSlotsWithOverlappingBooking"] = true;
settings["ConsiderSlotsWithLessThanRequiredDuration"] = true;
settings["ConsiderSlotsWithProposedBookings"] = true;
EntityCollection preferredResources = new EntityCollection();
Entity brbresource = new Entity();
brbresource.Attributes.Add("bookableresourceid", new Guid("c099b792-f9fb-ea11-a813-000d3aadc20a"));
preferredResources.Entities.Add(brbresource);
EntityCollection resourceTypes = new EntityCollection();
Entity resourceType = new Entity();
resourceType.Attributes.Add("resourcetypes", new OptionSetValue(3)); //User
resourceTypes.Entities.Add(resourceType);
Entity rescourseSpecificationEntity = new Entity("organization");
rescourseSpecificationEntity["PreferredResources"] = preferredResources;
rescourseSpecificationEntity["ResourceTypes"] = resourceTypes;
// Add to request object
resourceAvailabilityReq["Version"] = "1";
resourceAvailabilityReq["Settings"] = settings;
resourceAvailabilityReq["Requirement"] = newReqObject;
resourceAvailabilityReq["ResourceSpecification"] = rescourseSpecificationEntity;
OrganizationResponse resourceAvailabilityResp = obj.service.Execute(resourceAvailabilityReq);
Yes. I kept the specified resource as must choose from on the requirement.
Understood, makes sense. And just to double-check I assume you have specified the resource(s) as "must choose from", not preferred?
Yes. To get specified bookable resources time slots.
Initially we used msdyn_retrieveresourceavailability action to achieve this, but since this specified action is only for internal use. We are working on msdyn_searchresourceavailability action to get specified resources time slots.
Is your goal to only get the specified resource(s) or is it about the sorting?
I have replaced few of my code with your reference code, but still the preferred resources is not being considered, in the result getting slots of all bookable resources.
On Schedule Board, schedule assistant we have option on Preferred Resources, if we filter based on Bookable resource only those people will appear. The same we are expecting in Action, but it is not working.
I browsed the internal knowledgebase and found 2 things:
1) "PreferredResources is meant for instructing the scheduling assistant to rank preferred resources higher than others." - That explains why you get more results than expected.
2) Can you check if the below code helps you and provide feedback?
1 | private static OrganizationRequest ConstructSearchResourceAvailability(DateTime startWindow, DateTime endWindow, |
2 | Guid timeGroupId, int durationInMins, Guid[] characteristicsIds = null, Guid[] categories = null, Guid[] resourceIds = null) |
3 | { |
4 | var request = new OrganizationRequest("msdyn_SearchResourceAvailability"); |
request.Parameters["Version"] = "1.0.0"; | |
5 | request.Parameters["Version"] = "2"; |
6 | |
7 | var settingsEntity = new Entity("contact"); |
8 | settingsEntity["ConsiderSlotsWithLessThanRequiredCapacity"] = false; |
9 | settingsEntity["ConsiderSlotsWithProposedBookings"] = false; |
10 | request.Parameters["Settings"] = settingsEntity; |
11 | |
12 | var requirement = new Entity("msdyn_resourcerequirement"); |
13 | requirement["msdyn_allocationmethod"] = new OptionSetValue(192350001); |
14 | requirement["msdyn_fromdate"] = startWindow; |
15 | requirement["msdyn_todate"] = endWindow; |
16 | requirement["msdyn_remainingduration"] = durationInMins; |
17 | requirement["msdyn_timegroup"] = new EntityReference("msdyn_timegroup", timeGroupId); |
18 | request.Parameters["Requirement"] = requirement; |
19 | |
20 | var preferredResourcesCollection = new EntityCollection(); |
21 | var preferredResource = new Entity("bookableresource"); |
22 | preferredResource["value"] = resourceIds.First(); |
23 | preferredResourcesCollection.Entities.Add(preferredResource); |
24 | var specificationEntity = new Entity("contact"); |
specificationEntity["PreferredResources"] = preferredResourcesCollection; | |
25 | specificationEntity["MustChooseFromResources"] = preferredResourcesCollection; |
26 | request.Parameters["ResourceSpecification"] = specificationEntity; |
27 | |
28 | return request; |
29 | } |
Thanks for the Response Alexander.
In our use case, we need to share the bookable resource timeslots to the portal, so for that we need to send some specified resources time slots. As suggested on the requirement, I have added the Resource Preferences in that I added one bookable resource with Preference type has ("must choose from"), after that i referenced the requirement id in the call, but still i'm getting slots for all the bookable resources.
I'm just guessing here, but then the API was introduced we only had the notion of a preferred resource. In the meantime this was extended to allow separating "preferred" from mandatory ("must choose from") candidates. I don't know how that would change your API call, but what you might want to try is - instead of putting all details in your request - creating a resource requirement first (with "must choose from" resources) and then reference this requirement in your call.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,802 Super User 2024 Season 2
Martin Dráb 229,133 Most Valuable Professional
nmaenpaa 101,154