0

I have a list with a lookup column displayed as a dropdown menu in the NewForm allowing the user to pick a contact person retrieved by lookup to the contacts list, however this list will soon grow past the List View Threshold preventing the lookup. Increasing the threshold is not an option.

Therefore I'm looking at how to retrieve contacts by a query and populate the dropdown menu with these instead, but have been unable to figure out exactly how to accomplish this.

The query I need would be something along the lines of

SELECT Name FROM Contacts WHERE Contacts.school_id = [school_id]

Correction: Where [school_id] represents a property of the school where a button to make a new interaction is located which links to this newForm.

The lookup column resides on an interactions list representing interactions with contacts for a school

UPDATE 1

found this javascript code that seems to be able to retrieve a number of items from a list for me.

function retrieveListItems() {
    var clientContext = SP.ClientContext.get_current(); 
    var oList = clientContext.get_web().get_lists().getByTitle('Contacts');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><eq> <FieldRef Name=\'school_id\'/><Value Type=\'Text\'>[$school_id??]</Value>' + 
    '</eq></Where></Query><RowLimit>500</RowLimit></View>');

    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        
}

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nContact: ' + oList.get_item('Contact');
    }

    alert(listItemInfo.toString());

    document.getElementById('queryResults').innerHTML=listItemInfo.toString();
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

now in the CAML query I need to match the school_id property of the items to retrieve with the school_id property of a school. this property is transferred to my newForm via URL passing and retrieved like this

<ParameterBinding Name="school_id" Location="QueryString(school_id)"     DefaultValue=""/>

However that happens below the

which contains the script. will the variable still be saved in time to be used in the script?

how can I retrieve this asp variable into javascript?

When used in aspx it is referenced like this:

$school_id

but I imagine putting that into the script won't work.

2 Answers 2

0

You could use something like jQuery autocomplete to help with this. You'd want to get a dynamic data set by using web services and a CAML query to filter your contacts based on the selection of the school id. Once that is fetched and bound to your form field, people just start typing the username and options will appear.

0

You can get the variable from the querystring using

        JSRequest.EnsureSetup();
        var id = JSRequest.QueryString["School_id"];

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.