Functions not firing (seemingly) randomly

May 11, 2015 at 2:49 PM
Hello,

This is my first post here, so please let me know if I should be posting this elsewhere.

I am using SPServices on a new item form on my site in order to do a few things. I am using SPCascadeDropdowns twice to populate 2 child ddls from a single parent ddl, and I am using SPDisplayRelatedInfo to show some related fields from another list on the form when the user selects an item from a drop down.

The SPDisplayRelatedInfo piece of this code runs every time I load the page. The new div with the related fields shows up, and when I select an item, the related info fields load with the information from the related list.

However, the CompleteFunc for the SPDisplayRelatedInfo does not always seem to run. Same with the SPCascadeDropDowns functions. Sometimes, all of the code runs perfectly. Other times, only the SPDisplayRelatedInfo piece works (minus CompleteFunc).

All of the alerts fire every time. I am not receiving any SPServices Debug messages. I am using jQuery version 1.11.2 and SPServices 2014.2.

Any assistance you could provide would be greatly appreciated.
//Function created to pull some info from the div created by SPDisplayRelatedInfo.
function setDailyGallonLimit(){
alert("setDailyGallonLimit Starting");
//This line multiplies the AssetFuelCapacity by the Daily Transaction Limit to populate the Daily Gallon Limit
$("input[title='Daily Gallon Limit']").val($("#SPDisplayRelatedInfo_AssetID td:nth-child(2)").text() * $("input[title='Daily Transaction Limit']").val());
//This line multiplies the AssetFuelCapacity by the Daily Transaction Limit * 5 to populate the Weekly Gallon Limit
$("input[title='Weekly Gallon Limit']").val($("#SPDisplayRelatedInfo_AssetID td:nth-child(2)").text() * 5 * $("input[title='Daily Transaction Limit']").val());
alert("setDailyGallonLimit Ran");
};

$(document).ready(function()      
{
        
      alert("CDD1 Start");
      //Utilizes SPCascadeDropdowns.  Parent list is 'Locations'
       $().SPServices.SPCascadeDropdowns({   
       relationshipList: "Locations", 
       relationshipListParentColumn: "Region", 
       relationshipListChildColumn: "LocationName",
       parentColumn: "Region",
       childColumn: "Location",
       debug: true
      });
      alert("CDD1 End");
      
      alert("CDD2 Start");
      //Also utilizing SPCascadeDropdowns.  Parent list is 'Managers'
      $().SPServices.SPCascadeDropdowns({   
       relationshipList: "Managers", 
       relationshipListParentColumn: "Region", 
       relationshipListChildColumn: "MgrNameForLookup",
       parentColumn: "Region", 
      childColumn: "ApprovingMgr", 
       debug: true
      });
      alert("CDD2 End");

      //Utilize SPServices.SPDisplayRelatedInfo to pull in some fields from the Assets list
      //This function is the only one in this code file that works reliably
      alert("DisplayRelatedInfoStart");
      $().SPServices.SPDisplayRelatedInfo({
       columnName: "AssetID",
       relatedList: "Assets",
       relatedListColumn: "AssetID",
       relatedColumns: ["AssetFuelTypeCalc","AssetFuelCapacity","AssetEquipStatusCode"],
       displayFormat: "table",
       headerCSSClass: "ms-vh2",
       rowCSSClass: "ms-vb",
       numChars: 0,
       matchType: "Eq",
       CAMLQuery: "",
       matchOnId: false,     // Added in v0.7.1
       completefunc: setDailyGallonLimit, //definition above
       debug: true
      });
      alert("DisplayRelatedInfoEnd");
          
});
Thank you.
May 27, 2015 at 6:17 PM
The issue ended up having to do with the "Required Field" being appended to some of the field names when the page was rendered. If you are having the same issue, I'd view your page source to see if your fields have the text "Required Field" being appended to them.