I have a lookup field that works with the .js file isn't hooked up to the form. When the .js is hooked up to the form, which I click "Save" the Promotion Name field errors with "Value does not fall within the expected range". The server team has increased throttling. That's not the issue. It's somewhere in this rest api:

function getPromotionNames()
        //targets the list for the ajax
        var promostatus = "Current";
        var url =_spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('Retail%20Promotions')/items";
        //Builds the query, selects the Dept1 field for the title and the ID, with Name field for filtering
        var query = "?$top=500&$select=Title,Promotion_x0020_Name,Status";
        //query += "&$expand=Promotion_x0020_Name"; // only need to use the expand for lookup fields and peoplepickers
        query += "&$filter=Status eq '"+promostatus+"'";  // filter piece
        url += query;  // final query that combines the url with the query
        //console.log("Line 85: "+url);

            url: url,  // using the variable url from line 93
            method: "GET",
            // standard header stuff that must be here
                "accept": "application/json;odata=verbose",
        // the done is essentially the success function called a promise
            //console.log("The request was successful.");
            // Extracting our results from the request
            var result = data.d.results;
            var promotionarray = [];  // new empty array
            //console.log("Line 104:");
            //console.log("Line 106:");
            if(result.length == 0){
                alert("There are no Retail Promotions for the data submitted. Please click Cancel and start over.");
                return false;
            if(result.length > 0)
                    var thisID = this.Id;
                    var thisName = this.Promotion_x0020_Name;
                //pushes stuff into the empty array
                        Id: thisID,
                        Name: thisName
                        console.log("promotionarray: "+promotionarray);
                // removes all of the dropdown values but 0 which is the default selected value
                $("select[id^='Promotion_x0020_Name_'] option:gt(0)").remove();
                //console.log("Line 153 lookup field values removed");
                // start building the jquery
                var buildPromotions = $("select[id^='Promotion_x0020_Name_']");
                promotionarray.forEach( // iterating through the array that we pushed stuff into
                    function(value) { // value is a variable that each item gets assigned to as it iterates through
                    //console.log("Line 136: "+(JSON.stringify(value)));
                    buildPromotions.append($("<option></option>").attr("value", value.Id).text(value.Name)); // builds each option for the dropdown and populates the dropdown
        // only runs if an ajax call returns a failed/rejected promise
        .fail(function(XMLHttpRequest, textStatus, errorThrown){  // variable that it is assigning the failure message
            // While making the request there was an error.
            alert("An error has occurred while auto-filling the Promotion Name field. Please reach out to support to resolve this issue: "+ errorThrown);
            //console.log("Status: "+textStatus+", Error: "+errorThrown);

screen capture of form

  • Are you getting correct options under Promotion Name dropdown? Can you add screenshot after inspecting dropdown options? Commented Jun 18, 2022 at 14:28

1 Answer 1


In this line at the top of the function:

var query = "?$top=500&$select=Title,Promotion_x0020_Name,Status";

I needed to include the ID. The correct version looks like this:

var query = "?$top=500&$select=ID,Title,Promotion_x0020_Name,Status";

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.