Wednesday, January 10, 2018

Batch Job Execution MSCRM JavaScript Update

Hi All,

Code below mentioned for BULK Update of Batch Job in MSCRM 2016


function BulkUpdate(multipleEntityIds, destinationEntity) {
            var data = [];
            data.push('--batch_123456');
            data.push('Content-Type: multipart/mixed;boundary=changeset_BBB456');
            data.push('');
            for (var i = 0; i < multipleEntityIds.length; i++) {
                data.push('--changeset_BBB456');
                data.push('Content-Type:application/http');
                data.push('Content-Transfer-Encoding:binary');
                data.push('Content-ID:' + i);
                data.push('');
                data.push('PATCH ' + parent.Xrm.Page.context.getClientUrl() + '/api/data/v8.1/' + destinationEntity + '(' + multipleEntityIds[i].replace("{", "").replace("}", "") + ')' + ' HTTP/1.1');
                data.push('Content-Type:application/json;type=entry');
                data.push('');
                data.push('{ "pa_description":"' + descriptionValues + '" }');
            }

            //end of changeset
            data.push('--changeset_BBB456--');
            //end of batch
            data.push('--batch_123456--');
            var payload = data.join('\r\n');

            $.ajax(
            {
                method: 'PATCH',
                url: Xrm.Page.context.getClientUrl() + '/api/data/v8.1/$batch',
                headers: {
                    'Content-Type': 'multipart/mixed;boundary=batch_123456',
                    'Accept': 'application/json',
                    'Odata-MaxVersion': '4.0',
                    'Odata-Version': '4.0'
                },

                data: payload,
                async: false,
                success: function (data, textStatus, xhr) {
                    var splitstring = currentIds.split(",");
                    for (var i = 0; i < splitstring.length; i++) {
                        alert("Updated Successfully");
                    }
                },
                error: function (xhr, data, textStatus, errorThrown) {
                    alert(data, textStatus + " " + errorThrown);
                }
            });
        }

No comments:

Post a Comment

How to Run Microsoft Flow for Every one Month

Introduction: In this Blog we will see how to Run Microsoft Flow for Every one Month. Implementation Steps:   1. Navigate to  https://make.p...