This project has moved and is read-only. For the latest updates, please go here.

SPcascadedropdown in Newform

Mar 16, 2015 at 4:11 PM

I am using sharepoint 2010 and jquery 1.11.1, SPservices-2014.02. Cascading dropdown is working fine but the problem is iam using the cascading in Newform of a list.

After the newform is opened and then when i dropdown value is changed then the cascading is working but i have eventreceiver which change the firstdropdown while opening the newform. in this case the value is changing in the second dropdown, so i have change the first dropdown manuelly and the filtering works ?..

Do i need to include something in the javascript ?
$(document).ready(function() {
 var url = _spPageContextInfo.siteServerRelativeUrl;
     relationshipWebURL: url,
    relationshipList: "Supplier",
    relationshipListParentColumn: "AccountingUnit",
    relationshipListChildColumn: "SupplierID",
    parentColumn: "Buchungskreis",
    childColumn: "Kreditor",
    debug: false
    relationshipWebURL: url,
    relationshipList: "SupplierTermsOfPayment",
    relationshipListParentColumn: "TermsOfPaymentSupplierID",
    relationshipListChildColumn: "TermsOfPaymentName",
    parentColumn: "Kreditor",
    childColumn: "zahlungskonditionen",
    debug: false
Mar 16, 2015 at 4:22 PM
I'm not sure how the event receiver is playing with the cascading. The sequence of events is going to matter, of course.

Can you explain more about what the issue is?

Mar 17, 2015 at 10:34 AM
Hi Marc,

The first dropdown value is selected automatically using Eventreceiver when the newform is opened. When the eventreceiver set the selected value the second dropdown is not filtered automatically.




the first image is the new form where the value for the first dropdown Belegnummer is automatically selected but the second dropdown Buchungskreis is not filtered automatically. When i manually change the value of the belegnummer as shown is in image 2 then the value is filtered and displaying in second dropdown as in image 3.
Mar 17, 2015 at 2:32 PM
It must have something to do with the event receiver logic or the timing of the two things together.

Why not just set the value of the first dropdown in script after the call to SPCascadeDropdowns?

Mar 19, 2015 at 10:01 AM
Hi Marc,

That should be done using Event receiver for other reason because the value for the first dropdown is taking according the page layout querystring value and then the value is populated. Even when i refresh the Newform manuelly it's not working only when i change the first dropdown value the second dropdown value is populated ?. Maybe when i refresh the event receiver again set's the value in the first dropdown.

I dont know how to overcome this
Mar 19, 2015 at 5:54 PM
For the first drop down (the one set by the event receiver), try calling .change() on it after you set up the cascade dropdowns (and ensure after the event receiver code has run)

My assumption is that the event receiver updates the select box value but never triggers the Change event, which CascadeDropdown uses to adjust the list of values.

-- sent from mobile
Mar 20, 2015 at 2:23 PM
Paul's got a possible solution there.

Again, it all depends how your event receiver works. I'll still go back to the question of why you need the event receiver, though. Why not grab the query string value with script and populate the column that way?

Mar 20, 2015 at 5:02 PM
Hi Paul,

what do you mean by calling change()

my event receiver looks like this
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
        public override void ItemAdded(SPItemEventProperties properties)
            int invoiceId = Convert.ToInt32(_stCurrentContext.Request.QueryString["ID"]);
            string invoiceLookupValue = _stCurrentContext.Request.QueryString["InvoiceNumber"];

            if (invoiceId != 0)
                EventFiringEnabled = false;
                // Set the LookupID
                SPFieldLookupValue newValue = new SPFieldLookupValue(invoiceId, invoiceLookupValue);
                properties.ListItem["AttachedToInvoiceID"] = newValue;

                EventFiringEnabled = true;  


where should i or how should i call change().
Mar 21, 2015 at 1:35 AM
Can you post your JavaScript code. You need to use jQuery to find the first drop-down and then call .change() on it.

-- sent from mobile

Mar 23, 2015 at 8:23 AM
Edited Mar 23, 2015 at 5:14 PM
HI paul,

This is my Javascript code.
<script src="../../SiteAssets/AgfaHYDMediaScripts/jquery-1.11.1.js" type="text/javascript"></script>
<script type="text/javascript">
// This javascript sets the default value of a lookup field identified 
// by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
// identified by <<QUERYSTRING VARIABLE NAME>>


// Customize this javascript by replacing <<FIELD DISPLAY NAME>> and 
// <<QUERYSTRING VARIABLE NAME>> with appropriate values.
// Then just paste it into NewForm.aspx inside PlaceHolderMain


function fillDefaultValues() {
//  var qs =,;
  var qs =,;
var qs = (function(a) {
    if (a == "") return {};
    var b = {};
    for (var i = 0; i < a.length; ++i)
        var p=a[i].split('=', 2);
        if (p.length == 1)
            b[p[0]] = "";
            b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    return b;
 setLookupFromFieldName("Belegnummer", qs["InvoiceItemID"]);
//$("select[title$='Belegnummer']").attr('disabled', true);

function setLookupFromFieldName(fieldName, value) {
  if (value == undefined) return;
  var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
// if theSelect is null, it means that the target list has more than
// 20 items, and the Lookup is being rendered with an input element
  if (theSelect == null) { 
    var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
    ShowDropdown(; //this function is provided by SharePoint 
    var opt=document.getElementById(theInput.opt);
    setSelectedOption(opt, value);
    OptLoseFocus(opt); //this function is provided by SharePoint 
  } else {
    setSelectedOption(theSelect, value);

function setSelectedOption(select, value) {
  var opts = select.options;
  var l = opts.length;
  if (select == null) return;
  for (var i=0; i < l; i++) {
    if (opts[i].value == value) {
      select.selectedIndex = i;
      return true;
  return false;

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);
  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
      return tags[i];
  return null;


Apr 2, 2015 at 7:39 AM
Hi Marc,

I tried also populating first dropdown using Javascript as show above. Still it's not working and i have to manuelly change the first dropdown
Apr 2, 2015 at 2:26 PM
If your calls to the SPServices functions are working correctly without the event receiver, then it must be something in your event receiver causing the issue. As long as the values you need are on the query string, I'd suggest ditching the event receiver altogether than doing everything in script. That way you can control the sequence of things better.