D365 Scheduling : msdyn_SearchResourceAvailability – C# Working Code

Currently, we use Schedule Board/Assistant to find the availability of resources based on the requirement.

msdyn_SearchResourceAvailability SDK message has been recently released to build custom functionality around the resource availability finding.

Here’s the C# Working Code snippet:

Entity settings = new Entity(“organization”);
settings[“UseRealTimeResourceLocation”] = false;
settings[“ConsiderTravelTime”] = true;
settings[“ConsiderSlotsWithOverlappingBooking”] = false;
settings[“ConsiderSlotsWithLessThanRequiredDuration”] = false;
settings[“ConsiderSlotsWithProposedBookings”] = false;

var entityCollectionResourceType = new EntityCollection();
entityCollectionResourceType.Entities.Add(new Entity
{
Id = new Guid(),
LogicalName = “ResourceTypes”,
Attributes =
new AttributeCollection
{
new KeyValuePair(“value”, 8)
}
});

var entityCollectionTerritories = new EntityCollection();
entityCollectionTerritories.Entities.Add(new Entity
{
Id = new Guid(),
LogicalName = “territory”,
Attributes =
new AttributeCollection
{
new KeyValuePair(“territoryid”, workOrderDetails.TerritotyId)
}
});
var constraints = new Entity() { LogicalName = “organization”, Id = new Guid(),
Attributes = new AttributeCollection
{
new KeyValuePair(“Territories”, entityCollectionTerritories)
}
}; //Territories

Entity resourceSpecification = new Entity(“organization”);
resourceSpecification[“ResourceTypes”] = entityCollectionResourceType;
resourceSpecification[“RetrieveResourcesQueryId”] = new Guid(fpsActionRetrieveResourcesQueryId);// “e014219f-65c7-476c-88e0-da0e21d4048a”);
resourceSpecification[“Constraints”] = constraints;

var response = service.Execute(
new OrganizationRequest(“msdyn_SearchResourceAvailability”)//””msdyn_getresourceavailability”)
{
Parameters = {
{ “Version”, “1.0” },
{ “Requirement”, requirement},
{ “Settings”, settings},
{“ResourceSpecification”, resourceSpecification}
}
});
var timeSlots = (EntityCollection)response.Results[“TimeSlots”];

Leave a comment