Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Query the working hours of a user using QueryScheduleRequest

Posted on by 361

Hello,

I want to retrieve available hours so i can put a booking rule on the universal resource schedule board when execute my query it return this error : Expression expected at position 0 in ''.

 

this is my code

 var parameters = {};
    parameters.ResourceId = "8BF4DC80-6E5C-E911-A974-000D3A391A6A";
    parameters.Start = JSON.stringify(new Date("06/10/2019 03:30:00").toISOString());
    parameters.End = JSON.stringify(new Date("06/12/2019 08:00:00").toISOString());
    var timecodes1 = {};
    timecodes1 = "Microsoft.Dynamics.CRM.TimeCode.Available";
    parameters.TimeCodes = [timecodes1];

    var queryScheduleRequest = {
        ResourceId: parameters.ResourceId,
        Start: parameters.Start,
        End: parameters.End,
        TimeCodes: parameters.TimeCodes,

        getMetadata: function() {
            return {
                boundParameter: null,
                parameterTypes: {
                    "ResourceId": {
                        "typeName": "Edm.Guid",
                        "structuralProperty": 1
                    },
                    "Start": {
                        "typeName": "Edm.DateTimeOffset",
                        "structuralProperty": 1
                    },
                    "End": {
                        "typeName": "Edm.DateTimeOffset",
                        "structuralProperty": 1
                    },
                    "TimeCodes": {
                        "typeName": "Collection(mscrm.TimeCode)",
                        "structuralProperty": 4
                    }
                },
                operationType: 1,
                operationName: "QuerySchedule"
            };
        }
    };
    debugger;
    Xrm.WebApi.online.execute(queryScheduleRequest).then(
        function success(result) {
            if (result.ok) {
                debugger;
                var results = JSON.parse(result.responseText);
                return results; 
            }
        },
        function(error) {
            debugger;
            Xrm.Utility.alertDialog(error.message);
        }
    );



this is my rest api builder screenshot :

i don't know what should i put in the red circle

00213.Capture.PNG

*This post is locked for comments

  • Suggested answer
    Anas Rafik Profile Picture
    Anas Rafik 361 on at
    RE: Query the working hours of a user using QueryScheduleRequest

    I solved the problem by using this :

    var start = new Date(); //Put Start datetime here
     
    var end = new Date(); //Put End datetime here
    end.setDate(end.getDate() + 1);
     
    var requestUrl = "/api/data/v9.1/QuerySchedule(ResourceId=@p1,Start=@p2,End=@p3,TimeCodes=@p4)";
    requestUrl += "?@p1=" + Xrm.Page.context.getUserId().replace("{", "").replace("}", "");
    //put Id of resource you want get data for as parameter 1
     
    requestUrl += "&@p2=" + JSON.stringify(start).replace(/"/g, "");
    requestUrl += "&@p3=" + JSON.stringify(end).replace(/"/g, "");
    requestUrl += "&@p4=" + JSON.stringify(['0']);
     
    //For TimeCodes use '0' for Available
    //'1' for Busy
    //'2' for Unavailable
    //'3' for Filter
     
    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();
  • necsa Profile Picture
    necsa 3,455 on at
    RE: Query the working hours of a user using QueryScheduleRequest

    Hi Anas,

    Please take as a reference following page:

    docs.microsoft.com/.../querymultipleschedules

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans