Get ID of list item using Jquery/Javascript. Javscript is present on edit form of another list

Hi All,

Need your help.

I want to retrieve the list item id of another list depending on a value.

E.g I have list named "A", on whose edit form I will writing javascript. Using this Jquery/JavaScript I want to retrieve List Item ID of list named "B".

In List A, on edit form, its item ID is equal to one of the column in List B.

I will match this value and get the List item ID in list "B".

I have used following code but Item ID returned is undefined. Please let me know if below code is right or it needs modification.

var LibID=GetUrlKeyValue("ID");
  var queryLookup = "<View>><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>"+LibID+"</Value></Eq></Where><OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy><ViewFields><FieldRef Name='Title' /></ViewFields></Query></View>";

var itemID="";

// Call GetListItems to return the ID
$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "B",
    CAMLViewFields: "<ViewFields><FieldRef Name='ID'/></ViewFields>",
    CAMLQuery: queryLookup,
    completefunc: function(xData,Status) {
        //itemID = $(xData.responseXML.xml).find("z\\:row").attr("ows_ID");
          itemID = $(xData.responseXML).SPFilterNode("z:row").attr("ows_ID");
        //itemID = $(this).attr("ows_ID");
      }
   });

alert("itemID="+itemID);

Your help is appreciated as I am stuck on this.

Thanks & regards,

Manish

August 27th, 2015 12:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics