0

I have two lists: Catalog and Position.

I want to retrieve the value of a list item in Catalogand use it for the value of a list item in Position.

To get the list items' value Title, I used

// Get values from Catalogue list
function retrieveListItems() {
    var clientContext = new SP.ClientContext.get_current();
    catalogueList = clientContext.get_web().get_lists().getByTitle('Catalog');

    var camlQuery = new SP.CamlQuery(); // initiate the query object
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'Title\'/>' +
        '<Value Type=\'Text\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
    itemColl = catalogueList.getItems(camlQuery);
    // returns the item collection based on the query
    context.load(itemColl);
    context.executeQueryAsync(retrieveListItemsSuccess, retrieveListItemsFail);
}

function retrieveListItemsSuccess() {
    var listItemEnumerator = itemColl.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var listDetails = oListItem.get_item('Title') ;
        console.log("listDetails: " + listDetails);
    }

}
// This function is executed if the above call fails
function retrieveListItemsFail(sender, args) {
    alert('Failed to get list items. Error:' + args.get_message());
}

This will return different title strings, such as "Title1", "Title2" etc.

Using the following code, I want to set the value I got in the Position list:

var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Position');
var item = new SP.ListItemCreationInformation();

var oListItem = oList.addItem(item);
oListItem.set_item('Title', listDetails);

The problem I have is that I don't know what to change in camlQuery.set_viewXML, so that it returns the Title if the list item ID has a certain value (f.ex. 4). Right now it just returns the first 10 elements, but I want to get the value of a specific list item. How can one achieve this?

Thanks.

1 Answer 1

1

<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>{PUT YOUR LOOKUP ITEM ID HERE WITHOUT THESE CURLY BRACES}</Value></Eq></Where></Query></View>

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.