Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Answered

How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

Posted on by 15

With the depreciation of the existing service scheduling capabilities, to be replaced with the new unified scheduling engine. How, using the custom actions/api should we be querying the new scheduling engine to find available time slots?

How to get time slots using msdyn_SearchResourceAvailability API?

Any help would be greatly appreciated!

  • rajeev tiwari Profile Picture
    rajeev tiwari 410 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi Gabriel,

    We are using resource type crew to get res availability and tried using api provided by Microsoft but it doesn't honor filters like resourcespecification or preferred resources.

    Output is for all, clearly bug in MS api.

    Raised support ticket but they are not able to help us from last 2 months.

  • RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi, just want to say thank you, because I was not being able to properly configure the Characteristics on the Constraints, and because of this OLD reply of yours, I can!

    Not all heroes wear capes!

  • Gabriel Dias Junckes Profile Picture
    Gabriel Dias Junckes 2,435 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi Sudhir. 

    Yes, you can register this the plugin at any event. I haven't used it on Flow but I think could be a good idea. You may need to use a generic HTTP Request for it. 

    You could register on the Resource Requirement (async) but I don't recommend. There are a lot of Microsoft plugins running to create the calendar, adding the preferred resources and so on. 

  • Sudhir Shukla Profile Picture
    Sudhir Shukla 125 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi Gabriel,

    This code for the plugin is registered against which event on which entity? I'm assuming not the create/update of the resource requirement record.

    Also thanks so much for sharing your code, your help is super appreciated.

    Thanks,

    Sudhir

  • Abigail Profile Picture
    Abigail 550 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Follow these steps according to the sample.js file you create in Microsoft D365:.

    1. Modify the hard-coded input parameters provided in the sample.js file to reflect the GUIDs of records (for example, resources, characteristics, territories) in your org.
      • pastedimage1584955423639v1.png
    2. Add the files in the sample folder as web resources in your organization.
      • pastedimage1584955423640v2.png
      • pastedimage1584955423641v3.png
    3. Navigate to the newly added sample.htm page. It would look like <<YourOrgURL>>//WebResources/new_sample.htm.
      • pastedimage1584955423642v4.png
    4. Open the browser’s developer tools by using the F12 function key. Set breakpoints as needed and inspect the request/responses in the developer tool’s console.
      • pastedimage1584955423643v5.png
      • pastedimage1584955423644v6.png

     

    I hope this helps you!

    More over here :https://cloudblogs.microsoft.com/dynamics365/it/2019/07/15/how-to-use-resource-schedulings-search-resource-availability-api/

    Regards

  • Vamsi Patibandla Profile Picture
    Vamsi Patibandla 25 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi Gabriel, Could you please share the code. Thanks in advance.

  • abx Profile Picture
    abx 35 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi Gabriel,

    Have you tried "Roles" in constraint in above code that you have shared. If yes, did that work out?

  • Verified answer
    Gabriel Dias Junckes Profile Picture
    Gabriel Dias Junckes 2,435 on at
    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;
        }

  • Sabina Khanna Profile Picture
    Sabina Khanna 15 on at
    RE: How to get available time slots from new api URS(Unified resource Scheduling) using plug-ins/code

    Hi,

    Thanks for the reply.

    P.S -I need time slots through plugin/code not JavaScript.

    I went through both of these links but When I tried to assign an entity in "Settings" parameter I am getting an error "object reference not set to an instance of an object".

    Basically I didn't understand below line in the first link in "Settings" section.

    "Settings are specified as attributes in an entity bag. The type of does not matter, you can specify any entity logical name".

    What to pass in "Settings" parameter of "msdyn_SearchResourceAvailability" api ????

    Below are the input parameters for "msdyn_SearchResourceAvailability" API. Out of 4 parameters 3rd one is not clear.

    1. Version - string (Mandatory)

    2. Requirement - Need to pass "resource requirement" entity details (Mandatory)

    3. Settings - from which entity??? (Mandatory)

    4 ResourceSpecification - from which entity (Can skip this as not Mandatory)

  • Suggested answer
    ba365guy Profile Picture
    ba365guy 2,946 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans