0

I'm trying to retrieve a lookup field using :

var lookup = ($(this).attr("ows_shARePublishTo_x003a_shAReSiteUR"));

Other columns seem to work fine, including another lookup column

The column name is:

Field=shARePublishTo%5Fx003a%5FshAReSiteUR

But keep getting undefined when I alert lookup. it seemed to work fine before I added and removed column from Library and Content Type.

Any ideas?

Most of code:

        var sliderList = "shARe Applications"; // Name of the list that contains slides
        var ListContentField = "shAReAppDesc"; //Internal Name of the Rich text field that has slide content      

        var ListBackgroundImageField = "shARe_x0020_Application_x0020_Ic"; //Internal Name of the picture field to use as background image


        var ListTitle="Title";
        var ListLink = "shAReAppURL";


        var thisSite = $().SPServices.SPGetCurrentSite();
        var siteURL = thisSite + "/SRE";
        var build = new String();

          //query to retrieve all items
          var query = "<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Number'></Value></Neq></Where></Query>";


            $().SPServices({
                operation: "GetListItems",
                async: true,
                webURL: siteURL,

                listName: sliderList,
 //                 CAMLViewFields: camlViewFields ,


                CAMLQuery: query,
                completefunc: function(xData, Status) {
                   $(xData.responseXML).SPFilterNode("z:row").each(function() {

                    var slideTitle = ($(this).attr("ows_"+ListTitle));
                    var slideLink = ($(this).attr("ows_"+ListLink));
                    var slideContent = ($(this).attr("ows_"+ListContentField));



                    var picture = $(this).attr("ows_"+ListBackgroundImageField);

                    var filename = picture.substr((picture.lastIndexOf("/")+1),(picture.length)); 
                    var thisSite = $().SPServices.SPGetCurrentSite();
                    var DynamicImageUrl= thisSite+"/SRE/shAReApplicationImages/"+filename;




                    var link = slideLink.split(",")[0];
                    var linkText = slideLink.split(",")[1];



                    //var lookup = ($(this).attr("ows_shARePublishTo_x003A_shARe_x0020"));
                    //display names  !!!
                    var lookup = ($(this).attr("ows_shARePublishTo_x003a_shAReSiteUR"));
                    alert(lookup);
                    //var lookup = lookup +";";


                var lookupArray = lookup.split(";");
                    // get top location, as iFrame used location unknown unless top used.
                    var TopPath = (window.top.location.pathname).toLowerCase();


                     for(var i = 0; i < lookupArray.length; i++){
                    // alert (lookupArray[i]);
                      var SingleItem = lookupArray[i].toLowerCase();
                      var PublishTo=  SingleItem.substr(SingleItem.lastIndexOf("sites")-1,SingleItem.length); 


                        var TopPath1 =  TopPath.substr(0,(TopPath.lastIndexOf("sitepages")-1));
                        //alert ("URLTopFrame-"+TopPath1);

                        if (PublishTo == TopPath1)
                        {
                        //alert (slideTitle + "match");

                        $(".carousel").append("<ul style=\"background:#FFFFFF;\"><img src="+ DynamicImageUrl +" style=\"width:35%; height:50%;\"   /><span id =\"title\">" + slideTitle+    "</span><BR /><BR /> <div id = \"BodyText\">"+slideContent+ "<BR /><a target= \"_top\" href=\" "+link +" \"> "+ linkText +"</a> "+ "</div>" +"</ul>");





                        }



                     } //end lookup array




                    }); // end for each function              
3
  • Can you post the code on how $(this) is getting initialized? Have you Included that columns as part of context.load? Nov 27, 2014 at 13:12
  • Updated with code. Nov 27, 2014 at 13:27
  • Is the lookup a required field? Nov 27, 2014 at 13:30

1 Answer 1

0

Explicitly request for the field using CAMLViewFields property. Something like

var CAMLViewFields = "<ViewFields><FieldRef Name='shARePublishTo_x003a_shAReSiteUR'/>" +
    "</ViewFields>"

And use this in

$().SPServices({
    operation: "GetListItems",
    async: true,
    webURL: siteURL,
    listName: sliderList,
    CAMLViewFields: CAMLViewFields,
    ...
2
  • Hi That's worked I also had to add the other lookup in viewfields otherwise error occured (shARe_x0020_Application_x0020_Ic), Why did it work before, was it beacuse I have to add the coloumn in the default view? Nov 27, 2014 at 14:34
  • Yes. Also by default required fields also get included Nov 27, 2014 at 14:42

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.