What on earth is the issue with this camel case phrase?

Still getting the hang of using camel and running into issues. I can successfully execute two separate queries, but when I try to combine them, I encounter an error message. Even after reviewing the documentation, I am still unsure about what exactly is causing the problem.

Query1:

   var specifier1 = "<Where><Eq><FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'>" +
                           "<UserID/></Value></Eq></Where>";

Query2:

   var specifier2 = "<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>"+currentItemID+"</Value>"+
                           "</Eq></Where>";

Combined query:

   var specifier = "<Where><And><Eq><FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'>" +
                           "<UserID/></Value></Eq><And><Eq>"+
                           "<FieldRef Name='ID'/><Value Type='Text'>"+currentItemID+"</Value>"+
                           "</Eq></And></And></Where>";

The error message that pops up with the combined query states:

Request Failed.One or more field types are not installed properly. Go to the list settings page to delete these fields.
undefined

Once I set the string, I make the following calls. Could it be that a different approach is needed with AND conditions? It seems like things go awry in my enumerator loop's console.log. The error message consistently shows strings of 6's: xxxxxx

   camlQuery.set_viewXml("<View><Query>"+specifier+"</Query></View>");
   var collListItems = list.getItems(camlQuery);
   ctx.load(collListItems);
   ctx.executeQueryAsync(
        function(){
            var enumerator = collListItems.getEnumerator();
            count = collListItems.get_count();
            while(enumerator.moveNext()){
                var item = enumerator.get_current();
                console.log("xxxxxID : " + item.get_id());
            }
            if (count == 0) {
                LockDownCells();
            }
        },
        function(sender,args){
             console.log("xxxxxxRequest Failed."+args.get_message() + "\n" + args.get_stackTrace());
        }
    );

Answer №1

Check out this code snippet:

<Query>
   <Where>
      <And>
         <Eq>
            <FieldRef Name='ID'/>
            <Value Type='Text'>currentItemID</Value>
         </Eq>
         <Eq>
            <FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'>
            <UserID/></Value>
         </Eq>
      </And>
   </Where>
</Query>

Answer №2

Below is the revised code snippet.

<script type="text/javascript>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);
function retrieveListItems(){
    var currentItemID=2;     
    var listTitle="CL1017"; 
    var specifier = "<Where><And>"+
                     "<Eq><FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'><UserID/></Value></Eq>"+
                     "<Eq><FieldRef Name='ID'/><Value Type='Text'>"+currentItemID+"</Value></Eq>"+
                     "</And></Where>";

    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle(listTitle);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query>"+specifier+"</Query></View>");
    var collListItems = list.getItems(camlQuery);
    ctx.load(collListItems);
    ctx.executeQueryAsync(
        function(){
            var enumerator = collListItems.getEnumerator();
            count = collListItems.get_count();
            while(enumerator.moveNext()){
                var item = enumerator.get_current();
                console.log("xxxxxID : " + item.get_id());
            }
            if (count == 0) {
                //LockDownCells();
            }
        },
        function(sender,args){
             console.log("xxxxxxRequest Failed."+args.get_message() + "\n" + args.get_stackTrace());
        }
    );
}
</script>

If you intend to only query list items by Item ID, it's recommended to use the following code without the need for CAML Query.

<script type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);
function retrieveListItems(){
    var itemId=2;    
    var listTitle="CL1017";                          
    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle(listTitle);  
    var listItem = list.getItemById(itemId);
    ctx.load(listItem);
    ctx.executeQueryAsync(
        function(){
            console.log("xxxxxID : " + listItem.get_id());
        },
        function(sender,args){
             console.log("xxxxxxRequest Failed."+args.get_message() + "\n" + args.get_stackTrace());
        }
    );
}
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring an element matches the height of its child using CSS styling

How can I ensure that the parent element's height adjusts to match the height of its child element using CSS? <div class = "parent"> <div class="child"> </div> </div> ...

triggers an unexpected error in console.log

I need help with the following code: function printName(obj) { console.log(obj.name); } printName({ name: "myName" }); (function displayError(errorMsg){ console.log(errorMsg); })("Error"); However, when I try to run this code, I am encountering a T ...

Using Sequelize to Link Two Columns Between Tables

In my sequelize database, I have the following table settings: const Accounts = sequelize.define('Accounts', { name: DataTypes.STRING, }); const Transfers = sequelize.define('Transfers', { value: { type: DataTypes.DECIMAL(10, ...

Is there a convenient method to combine arrays of objects in JavaScript using ellipses or an equivalent approach?

let array = [ {id: 1, data: {foo: "bar 1"}}, {id: 2, data: {foo: "bar 2"}} ]; //If ID doesn't exist, add new element to the array array = [...array, {id: 3, data: {foo: "bar 3"}}] console.log(array); //If ID exists, replace data object with new ...

encountering difficulties when trying to install npm packages in node.js

Starting out with Node.js and new to installing packages like express.js and underscore.js using NPM. However, every time I attempt to install using the following commands: npm install express, npm install underscore I keep encountering errors. Please ...

Is it feasible to simultaneously activate a modal and launch a URL in a separate tab when a link is selected?

I have 4 buttons, stylized to look like actual buttons, but only two of them are relevant: The first button opens a link in a new tab with its respective URL and the attribute target="_blank". The second button triggers a modal window containing text ...

The Autofocus feature in HTML5 is malfunctioning in Internet Explorer 9

I am currently working on a project for IE9, and I am having trouble with the HTML5 autofocus keyword not functioning as expected. Specifically, the autofocus feature that puts the cursor in the specified input field is not working in IE9 (and I am forced ...

Leveraging an external global variable file that is not incorporated into the bundle

I have a JavaScript file dedicated to internationalization. I am looking for a way to provide this file to clients for them to edit without requiring me to rebuild the entire project. Currently, I store this file in the static folder so it is included in ...

Execute Javascript after modification of the DOM

I have developed two custom directives known as app-content and app-content-item. These directives are intended to be utilized in upcoming projects to provide a basic structure with simple styling. They will be incorporated into a module and should be nest ...

Steps to incorporate / insert Angular directive in an application

In my app, the main.js file is located in the root folder. -app |_ routes.js |_ main.js -components |_directives |_abc-directive.js I am trying to figure out how to define a directive that can be accessed from a different folder. This is what I at ...

Determine the position of a particular td element within its parent tr using jQuery

Can someone help me with a jQuery solution to identify the descendant number (below 3) within a specific column in a table, as shown in the example below? $(".colclass").click(function (e) { //code to find the td descendant number to tr, whic ...

Storing POST Request Data in Express

I want to use a single API endpoint for both GET and POST requests. My goal is as follows: Send multiple POST requests to /api/users with data like: {'id': 2, is_valid: 'true'} Retrieve this data by fetching the same API URL later on ...

What are the reasons behind the jQuery file upload failing to work after the initial upload?

I am currently utilizing the jQuery File Upload plugin. To achieve this, I have hidden the file input and set it to activate upon clicking a separate button. You can view an example of this setup on this fiddle. Here is the HTML code snippet: <div> ...

The issue with `Meteor` createContainer not rendering in React is causing trouble

I have been attempting to dynamically retrieve data from a mongo database, with the goal of updating the client side automatically whenever new data is inserted. Initially, I used Tracker.autorun in the main.js file within the client directory, and it su ...

Execute Function after Gridview Sorting

While working on a gridview within an update panel, I encountered a scenario where the gridview successfully resorts itself upon clicking on the column header. However, post-sorting, I wish to execute a JavaScript function named MyScript. Any suggestions ...

What is the best way to empty input, select, and textarea fields after performing a clone operation

I am currently working on creating a form to display items and need a fresh text field when the user clicks the ADD button. function addNewItem() { //ADD ROW AND CLONE var table = document.getElementById('tbl'); var tbody = document.create ...

There is no assigned value in scope for the shorthand property. You must either declare one or provide an initializer

I'm just starting out with TypeScript. Encountering the error 'No value exists in scope for the shorthand property 'firstName'. Either declare one or provide an initializer.' while using Prisma with Next.js to create a new user in ...

Odd behavior of the "for in" loop in Node.js

It seems like I'm struggling with the use of the "for in" statement. When working with a JSON document retrieved from a mongodb query (using nodejs + mongoose), its structure looks something like this: [{ "_id":"596f2f2ffbf8ab12bc8e5ee7", "da ...

Accessing the locally stored data and displaying it in ng-bind

My journey to learn javascript through this project has hit a roadblock. I have stored an exchange rate in local storage: localStorage.gbpUSD = "1.42746"; Now, I want to utilize it instead of the hardcoded exchange rate in the code below... <input t ...

Is it possible to retrieve JSON data from a Google Doc Spreadsheet using jQuery without having to make the document public?

I am attempting to retrieve data from a Google Doc Spreadsheet using javascript and jQuery in order to perform calculations with the numerical values. Below is the code I have used successfully for public spreadsheets: function getData(key, wid, f) { ...