Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing an issue when inserting records in to multiple lists using rest api with http calls in SharePoint 2013.

I have written common method mentioned below which will take input params as data and url.

JavaScript
var postRequest = function (data, url) {
               var deferred = $q.defer();
               $http({
                   url: baseUrl + url,
                   method: "POST",
                   headers: {
                       "Accept": "application/json;odata=verbose",
                       "Content-Type": "application/json;odata=verbose",
                       "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
                       "If-Match": "*"
                   },
                   data: JSON.stringify(data)
               }).success(function (result) {
                   alert(result.d.Id);
                   deferred.resolve(result.d.Id);
               }).error(function (result, status) {
                   alert(status + result);
                   deferred.reject(status);
               });
               return deferred.promise;
           };

Using the above code I am inserting data in to list A, once record has been inserted in to list a, With item id of I am inserting record in list b with additional fields and list C.

I am calling above common method which is mentioned as below.

JavaScript
$scope.submitData = function (LSSDeal, lssIds, amIds) {
            var submitDataPromise = lssDealService.submitLSS(LSSDeal, lssIds, amIds);
            submitDataPromise.then(function (transactionResponse) {
                var transactionId = transactionResponse;
                $scope.AddtoPaymentList(LSSDeal, transactionId);
                $scope.AddToHistory(LSSDeal, transactionId);

            }, function (error) {
                alert("error in submitting transaction data" + error);
            });
        };

I am able to get transaction id for first request which will insert record in list A.After getting ID I am calling remaining two methods.

JavaScript
$scope.AddtoPaymentList = function (LSSDeal, transactionId) {
               var paymentlistPromise = lssDealService.saveToPaymentList(LSSDeal, transactionId);
               paymentlistPromise.then(function (paymentlistResponse) {
                   var paymentId = paymentlistResponse;
                   alert("LSS Deal has been Added to payment list with transaction Id:" + transactionId);
               }, function (error) {
                   alert("error in inserting payment list data" + error);
               });
           };
           $scope.AddToHistory = function (LSSDeal, parentListId) {
               var historyPromise = lssDealService.saveToHistory(LSSDeal, parentListId);
               historyPromise.then(function (historyResponse) {
                   var historyId = historyResponse;
                   alert("LSS Deal has been Added to history with history Id:" + historyResponse);

               }, function (error) {
                   alert("error in inserting history data" + error);
               });

           };

For remaining two methods I am always getting error message as status zero and data null.

Simply for second request on wards its going error block but records are inserting successfully.

But when I am debugging getting success messages. Please guide me.

Thanks in advance.

References: http://www.codeproject.com/Articles/1002526/SharePoint-and-Angularjs

What I have tried:

I have tried by changing http call with ajax call and timeout option.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900