1
votes

Im trying to use a javascript to search a Sharepoint list for a person with the name "John". It seems as if the query fails because I get an alert with the error: Request failed. One or more field types are not installed properly. Go to the list settings page to delete these fields. undefined

This suggests that the script ends up in the onQueryFailed()-method. I cant find anything wrong with the CAML and the internal column names are used.

Code from .aspx:

<script type="text/javascript">
            function MyJavascript() {
            var siteUrl = '/sites/MySite/';
            var clientContext = new SP.ClientContext(siteUrl);
            var oList = clientContext.get_web().get_lists().getByTitle('People');

            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="\'Name\'"/>' +
            '<Value Type=\'Text\'>John</Value></Eq></Where></Query></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 += '\nID: ' + oListItem.get_id() +
                '\nName: ' + oListItem.get_item('Name') +
                '\nAge: ' + oListItem.get_item('Age');
            }

            alert(listItemInfo.toString());
        }

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

        </script> 

Code from the .cs that registers the script to a button:

SubmitButton.Attributes.Add("onclick", "MyJavascript(); return false;");

Any ideas?

1
What is the internal name of the field you are querying? Are you sure it is Name?Servy
@Servy Yes, the internal name is Name.user1666361
Can you access the list on SharePoint using web browser and go into this list? If acceptable, please also try to change the name of Name field into something more unique, like PersonName to be sure you've not used a reserved field name.Lukasz M
Thanks but just solved it myself. Faulty quotation marks were present in the FieldRed-parameter.user1666361

1 Answers

0
votes

Try putting ExecuteOrDelayUntilScriptLoaded(MyJavaScript, "sp.js"); directly below your siteUrl variable.