I would like to retrieve values from a lookup column (pull down) using SPServices() and load an array in javascript. This is available only in Newform.aspx. How can I do this?
2 Answers
Instead of looking at it as pulling values from a lookup column, pull values from the list the lookup column is referencing.
here's a quick example of pulling out records and loading a drop down list
$().SPServices({
operation: "GetListItems",
listName: "Business Types",
async: false,
CAMLViewFields: "<ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='RequiredDocuments'/></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ParentType' /><Value Type='Choice'>" + bizType + "</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
var tmp = "";
var subTypes = $("#ddlBusinessSubtype");
subTypes.find("option").remove(); //clear out the existing ones if they exist
$(xData.responseXML).find("[nodeName='z:row']").each(function () {
subTypes.append("<option value='" + $(this).attr("ows_ID") + "'>" + $(this).attr("ows_Title") + "</option>");
});
setSubtypeValues();
}
});
HTH
-
i Tried this but it is not working .. What is the BIZ TYPE??? in the query field??.. Can you please let me know.. I do have the same requirement. Commented Jan 28, 2014 at 13:20
When we create lookup fields in SharePoint for example the column will be like bellow:
if we have a Position List and we have employee info which has a lookup column position OfficeDescription you could get it like bellow code
your ViewFields:
<FieldRef Name='Position_x003a_OfficeDescription />
x003a is actually :
so you get it like bellow code:
var Position: $(this).attr("ows_Position_x003a_OfficeDescription");
This will bring the Id of position field along the title then you can use scripting techniques to clean get title only hope this helps someone who needs it, thanks