0

Title | Priority | Status

title1 | priority1 | status1

This is what my list looks like, If I get the "status1" from Status, how do i get the ID of the items row?

what I want to do is having an on-click(onselected) on the status item I'm getting from the list, and through the ID get the value of Title1 on the same row. this must be possible? so far i've tried the following code:

function RetrieveListItems() {
var query = new SP.CamlQuery();

query.set_viewXml("<View>" +
"<Query>" +
"<Where>" +
//"<And>" +
"<Eq><FieldRef Name='Status'/><Value Type='Text'>Skapad</Value></Eq>" +
//"<Eq><FieldRef Name='Assigned_x0020_to'/><Value Type='Lookup'>"+ theuser +"</Value></Eq>" +
//"</And>" +
"</Where>" +
"</Query>" +
"</View>");

listItems = list.getItems(query);

context.load(listItems, 'Include(Status, ID)');

context.executeQueryAsync(OnSuccess2, OnFail)
}
function OnSuccess2() {
var OnGoing = document.getElementById('OnGoing');

OnGoing.options.length = 0;

var listEnumerator = listItems.getEnumerator();

while (listEnumerator.moveNext()) {

    var currentItem = listEnumerator.get_current();

    OnGoing.options[OnGoing.options.length] = new     Option(currentItem.get_item("Status"), currentItem.get_item("ID"));
    //var id = $(this).find('option:selected').attr('id');
}

}
function doSomething() {
var id = $(this).find('option:selected').attr('ID');
var query = new SP.CamlQuery();

query.set_viewXml("<View>" +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq><FieldRef Name='Title'/><Value Type='Text'></Value></Eq>" +
"<Eq><FieldRef Name='ID' LookUpId='TRUE'/><Value Type='Counter'>" + id + "</Value></Eq>" +
"</And>" +
"</Where>" +
"</Query>" +
"</View>");

listItems1 = list.getItems(query);

context.load(listItems1);

context.executeQueryAsync(OnSuccessdoSomething, OnFail)
}
function OnSuccessdoSomething() {
var ListEnumerator = listItems.getEnumerator();
while (ListEnumerator.moveNext()) {
    var currentItem = ListEnumerator.get_current();
    var Description = currentItem.get_item('Title');
}
$("#divDescription").html(listItems1);
11
  • Please post code you have tried so far. Commented May 18, 2015 at 12:43
  • Does Title link to item? If so the url may contain the item id.
    – wjervis
    Commented May 18, 2015 at 12:45
  • @AmalHashim I've posted the code I've tried so far.
    – Dr Cox
    Commented May 18, 2015 at 12:50
  • @wjervis it does not link to the item, it's a "description" pretty much, I'm trying to get the description columns value through the status item of the same row.
    – Dr Cox
    Commented May 18, 2015 at 12:52
  • Are you trying on Select change get the Title value? Commented May 18, 2015 at 13:56

2 Answers 2

0

You can get he ID by:

var ID = currentItem.get_id();
2
  • does this get me the ID of the items "row" or does this give me the ID of the actual item? I want to get the ID of the row so i can get Title from the same row as the selected Status.
    – Dr Cox
    Commented May 18, 2015 at 14:05
  • It gives the ID of the item from which you can get the Title also.
    – Keerthi
    Commented May 18, 2015 at 14:09
0

I believe fixing below function can get you title

function OnSuccessdoSomething() {
    var ListEnumerator = listItems.getEnumerator();
    while (ListEnumerator.moveNext()) {
        var currentItem = ListEnumerator.get_current();
        var Description = currentItem.get_item('Title');

        $("#divDescription").html(Description);
        break;
    }
}
3
  • I get the following error: The Property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
    – Dr Cox
    Commented May 18, 2015 at 14:02
  • Thank you for taking your time to help me by the way, I really appreciate it.
    – Dr Cox
    Commented May 18, 2015 at 14:03
  • Change this line context.load(listItems, 'Include(Status, ID)'); to context.load(listItems, 'Include(Title,Status, Id)');
    – Keerthi
    Commented May 18, 2015 at 14:08

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.