Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error while performing a batch operation using Web API

(0) ShareShare
ReportReport
Posted on by 17,076

Hi All,

I am trying to perform a Web API batch update operation using Javascript. I am getting the error as "Incorrect attribute value type System.Decimal". Please find the below code which I am using for update.

function UpdateTimeCardEntries(selectedItemIds) {
    debugger;
    var data = [];
    data.push('--batch_123456');
    data.push('Content-Type: multipart/mixed;boundary=changeset_BBB456');
    data.push('');
    if ($('#lunchentryoptionset').val() == "961360000") {
        var end = new Date($('#enddatetime').val());
        end.setMinutes(end.getMinutes() - end.getTimezoneOffset());
        var lunchStart = new Date($('#lunchstartdateandtime').val());
        lunchStart.setMinutes(lunchStart.getMinutes() - lunchStart.getTimezoneOffset());
        var lunchEnd = new Date($('#lunchenddateandtime').val());
        lunchEnd.setMinutes(lunchEnd.getMinutes() - lunchEnd.getTimezoneOffset());
        for (var i = 0; i < selectedItemIds.length; i++) {
            var id = (i + 1);
            data.push('--changeset_BBB456');
            data.push('Content-Type:application/http');
            data.push('Content-Transfer-Encoding:binary');
            data.push('Content-ID:' + id);
            data.push('');
            data.push('PATCH ' + parent.Xrm.Page.context.getClientUrl() + '/api/data/v9.1/nth_timecardentries(' + selectedItemIds[i].replace('{', '').replace('}', '') + ') HTTP/1.1');
            data.push('Content-Type:application/json;type=entry');
            data.push('');
            var timeCard = {};
            timeCard.nth_end = end.toISOString();
            timeCard.nth_lunchentry = parseInt($('#lunchentryoptionset').val());
            timeCard.nth_lunchstart = lunchStart.toISOString();
            timeCard.nth_lunchend = lunchEnd.toISOString();
            data.push(JSON.stringify(timeCard));
        }
    }
    else {
        var end = new Date($('#enddatetime').val());
        end.setMinutes(end.getMinutes() - end.getTimezoneOffset());
        for (var i = 0; i < selectedItemIds.length; i++) {
            var id = (i + 1);
            data.push('--changeset_BBB456');
            data.push('Content-Type:application/http');
            data.push('Content-Transfer-Encoding:binary');
            data.push('Content-ID:' + id);
            data.push('');
            data.push('PATCH ' + parent.Xrm.Page.context.getClientUrl() + '/api/data/v9.1/nth_timecardentries(' + selectedItemIds[i].replace('{', '').replace('}', '') + ') HTTP/1.1');
            data.push('Content-Type:application/json;type=entry');
            data.push('');
            var timeCard = {};
            timeCard.nth_end = end.toISOString();
            timeCard.nth_lunchentry = parseInt($('#lunchentryoptionset').val());
            data.push(JSON.stringify(timeCard));
        }
    }
    data.push('--changeset_BBB456--');
    data.push('--batch_123456--');
    var payload = data.join('\r\n');
    var req = new XMLHttpRequest();
    req.open("POST", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.1/$batch", false);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "multipart/mixed;boundary=batch_123456");
    req.setRequestHeader("Prefer", "odata.maxpagesize=1");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                debugger;
                alert("The selected time card entries are successfully signed out.");
                window.top.opener.Xrm.Page.getControl("crmGrid").refresh();
                window.close();
            }
            else {
                alert(this.responseText.match('message":"(.*)","innererror"')[1]);
            }
        }
    };
    req.send(payload);
}


Any help is appreciated.

*This post is locked for comments

  • Suggested answer
    Dharanidharan Profile Picture
    Dharanidharan 390 User Group Leader on at
    RE: Error while performing a batch operation using Web API

    you are setting a field with the wrong type

    or you have a decimal field that you are not setting as decimal. Can you please check the datatype of the fields for those who are setting values

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans