0

As I am making few call to the endpoints within a function and it was causing issue with the parallel calls to the endpoints, so it was suggested in the other question to use the promise chaining. I updated my code so we can call the endpoints one after the other, so the code looks like below

 $scope.getRequest = function () {
        var url = $rootScope.BaseURL;
        var config = {
            headers: {
                'Authorization': `Basic ${$scope.key}`,
                'Prefer': 'odata.maxpagesize=2000'
            }
        };
        $http.get(url, config)
            .then(newViewRequest)
            .then(function(response){ 
                $scope.viewRequest.data = response.data;
            },
            function (response) { // failure async
                console.log("There was an error getting the request from CORE");});
   };

    var newViewRequest = function (response) {
        var url1 = $rootScope.BaseURL + `CMQ_REQUEST('${$scope.viewRequest.barcode}')`;
        if (response.data.REV_SAMPLE_CMQREQUEST.length = 0) {
            return $http.get(url1, config)
         }
        return $q.reject({ message: 'Validations didnt work' });
    };

It always sends the reject message back from the newViewRequest if response.data.REV_SAMPLE_CMQREQUEST.length = 0, if I comment it out I get the response.data is undefined.

enter image description here

1 Answer 1

2

Update your condition to validate instead of assigning

Issue: Update if condition as below to check response.data.REV_SAMPLE_CMQREQUEST.length whether it is 0 or not with === instead of =

if (response.data.REV_SAMPLE_CMQREQUEST.length === 0) 
Sign up to request clarification or add additional context in comments.

7 Comments

thank you but the issue is I dont get the response back with the $http.get call with in the If condition. I added the screenshot
@trx, try to console.log response1
The logs looks good. How can I get the response from the newViewRequest in to the $scope.viewRequest.data because response.data is undefined
please share the console.log for response1
Updated the screenshot
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.