RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code
Hi Sabina.
I am using C# to call the API and it worked fine for me, I will share my code and happy to help if you need.
public OrganizationRequest Create()
{
var req = new OrganizationRequest()
{
RequestName = "msdyn_searchresourceavailability"
};
// Resource Requirement
Entity newReqObject = new Entity("msdyn_resourcerequirement");
newReqObject["msdyn_fromdate"] = new DateTime(2019, 11, 11, 8, 30, 0, DateTimeKind.Local).ToUniversalTime();
newReqObject["msdyn_todate"] = new DateTime(2019, 11, 15, 17, 30, 0, DateTimeKind.Local).ToUniversalTime();
newReqObject["msdyn_remainingduration"] = 30;
newReqObject["msdyn_duration"] = 30;
// These three fields are not in the document but you use to filter the location
newReqObject["msdyn_worklocation"] = new OptionSetValue(690970000);
newReqObject["msdyn_latitude"] = -43.50185;
newReqObject["msdyn_longitude"] = 172.59811;
// Settings
Entity travelRadius = new Entity("travelradius");
travelRadius["Value"] = 50;
travelRadius["Unit"] = 192350001;
Entity settings = new Entity("systemuser");
settings["MaxResourceTravelRadius"] = travelRadius;
settings["ConsiderTravelTime"] = true;
settings["UseRealTimeResourceLocation"] = true;
// Rescourse Specification
var rescourseSpecificationEntity = new Entity
{
LogicalName = "systemuser"
};
EntityCollection characteristicsUnitEntityCollection = new EntityCollection();
Entity characteristic1 = new Entity();
characteristic1.Attributes.Add("characteristic", new EntityReference("characteristic", new Guid("98e62c87-f7d1-4c4b-bca7-9531ae91da99")));
characteristicsUnitEntityCollection.Entities.Add(characteristic1);
Entity characteristic2 = new Entity();
characteristic2.Attributes.Add("characteristic", new EntityReference("characteristic", new Guid("98e62c87-f7d1-4c4b-bca7-9531ae91da99")));
characteristicsUnitEntityCollection.Entities.Add(characteristic2);
//Territories
EntityCollection territoriesEntityCollection = new EntityCollection();
Entity territory = new Entity();
territory.Attributes.Add("territory", new EntityReference("territory", new Guid("98e62c87-f7d1-4c4b-bca7-9531ae91da99")));
territoriesEntityCollection.Entities.Add(territory);
//Teams
EntityCollection teamsEntityCollection = new EntityCollection();
Entity team = new Entity();
team.Attributes.Add("team", new EntityReference("team", new Guid("98e62c87-f7d1-4c4b-bca7-9531ae91da99")));
teamsEntityCollection.Entities.Add(team);
//Business Units
EntityCollection BUEntityCollection = new EntityCollection()
{
[0] = new Entity("businessunit", new Guid("98e62c87-f7d1-4c4b-bca7-9531ae91da99"))
};
// Add to constraint
var constraintEntity = new Entity("systemuser");
constraintEntity.Attributes.Add("Characteristics", characteristicsUnitEntityCollection);
constraintEntity.Attributes.Add("BusinessUnits", BUEntityCollection);
constraintEntity.Attributes.Add("Territories", territoriesEntityCollection);
constraintEntity.Attributes.Add("Teams", teamsEntityCollection);
rescourseSpecificationEntity.Attributes.Add("Constraints", constraintEntity);
// Add to request object
req["Version"] = "1";
req["Settings"] = settings;
req["Requirement"] = newReqObject;
// Optional - Use it to filter the resources
req["ResourceSpecification"] = rescourseSpecificationEntity;
return req;
}