web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Error on getting QueryMultipleSchedules

(0) ShareShare
ReportReport
Posted on by 5

Hello everyone,
I have one problem on getting Schedule for multiple users at once using "QueryMultipleSchedules" function i previously used "QuerySchedule" function to get single users Working hours but it is not feasible to get 100 Users working hours at once.
 - So i tried "QueryMultipleSchedules" documentation and Code in CRM Rest builder but when i execute that code i get below error.
Can someone help me out with this problem or how can i perform this function in better way.
- Also how can i pass multiple resource id in api Request.


Error:


    - bad Request:
        - Expected literal type token but found token '{\"REPLACE_WITH_PRIMARY_ID_ATTRIBUTE\":\"0\",\"@odata.type\":\"Microsoft.Dynamics.CRM.TimeCode\"}'."


Code(JQuery):


$.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: Xrm.Page.context.getClientUrl() + "/api/data/v9.1/QueryMultipleSchedules(Resource=@Resource,Start=@Start,End=@End,TimeCodes=@TimeCodes)?@Resource={\"resourceid\":\"123-456-789-123-456-78\",\"@odata.type\":\"Microsoft.Dynamics.CRM.resource\"}&@Start=2020-10-20T01:00:00.000Z&@End=2020-10-31T03:30:00.000Z&@TimeCodes={\"REPLACE_WITH_PRIMARY_ID_ATTRIBUTE\":\"0\",\"@odata.type\":\"Microsoft.Dynamics.CRM.TimeCode\"}",
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
            XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        async: true,
        success: function (data, textStatus, xhr) {
            var results = data;
        },
        error: function (xhr, textStatus, errorThrown) {
            Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
        }
    });

I have the same question (0)
  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Please try this code instead.

    function callMulitpleSchdule(){
    var start="2020-10-20T01:00:00.000Z";
    var end="2020-10-31T03:30:00.000Z";
     
    var requestUrl = "/api/data/v9.1/QuerySchedule(ResourceId=@p1,Start=@p2,End=@p3,TimeCodes=@p4)";
    requestUrl  = "?@p1="   Xrm.Page.context.getUserId().replace("{", "").replace("}", "");
    
     
    requestUrl  = "&@p2="   JSON.stringify(start);
    requestUrl  = "&@p3="   JSON.stringify(end);
    requestUrl  = "&@p4="   JSON.stringify(['0']);
     
     
    var req = new XMLHttpRequest();
    req.open("GET", context.getClientUrl()   requestUrl, true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
     
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                //you've got results to results variable
            } else {
                var errorText = this.responseText;
                //handle error here
            }
        }
    };
    req.send();
    }

    Best Regards,

    Leo

  • AdilShaikh1319 Profile Picture
    5 on at

    HI Leo Zhang ,

    Thank you for reply

    i already tried this code and it is working for me but it will only get schedule for single user at a time.

    i want to get the availability of multiple users at a same time.

    I hope you understand my case.

    Thank you

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans