Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm having an issue when I'm trying to grab a column I made in the tasks list (it's a lookup column). for some reason when i'm try to access it with javascript i always get an exception that it isn't initialized. i run the caml query and that run ok, and i am able to get some information from the task list, like title and status, but not the column i made.

Here is my code. The problem comes in when i try to access "Contact ID" in the linkInfo method. any help would be great. Thank You.

function test() {

         var newClientContext = new SP.ClientContext.get_current();

        var oWebsite = newClientContext.get_web();
        this.collList = oWebsite.get_lists();

        var Caml = new SP.CamlQuery();
        var taskCaml = new SP.CamlQuery();

        Caml.set_viewXml('<View></View>');

        var getContactList = oWebsite.get_lists().getByTitle("Contacts");
        var getTasksList = oWebsite.get_lists().getByTitle("Tasks");

        this.contactList = getContactList.getItems(Caml);
        this.taskList = getTasksList.getItems(Caml);

        newClientContext.load(contactList);
        newClientContext.load(taskList);

        newClientContext.executeQueryAsync(Function.createDelegate(this, this.linkInfo), Function.createDelegate(this, this.onQueryFailed));

    }


    function linkInfo() {

        var contactEnum = contactList.getEnumerator();
        var taskEnum = taskList.getEnumerator();
        var holder = '<br/>';
        alert(contactList.get_count());
        while (contactEnum.moveNext())
        {
            var oContact = contactEnum.get_current();
            holder += oContact.get_item('Title')+": ";

            while (taskEnum.moveNext()) {
                var oTask = taskEnum.get_current();

                if (oContact.get_id() == oTask.get_item('Contact ID')) {
                     holder += oTask.get_item('Title') + ", " ;
                }

            }

            holder += "<br/>";
            taskEnum = taskList.getEnumerator();
        }
        document.getElementById("visualization").innerHTML = "<p>" + holder + " </p>";
    }
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I think the issue is with your referencing the Display Name of the column instead of the Internal name. In the get_item() method, you will have to pass the Internal name of the Contact ID field. It will never contain spaces. It should most probably be something like Contact_x0020_ID. You can find out the exact internal name of the column with the steps mentioned in the following link:

https://www.nothingbutsharepoint.com/sites/devwiki/SP2007Dev/Pages/Getting%20the%20Field%20by%20the%20Internal%20Name.aspx

share|improve this answer
    
Thank You, you're right. I checked the source and the ID of my field was as you said it was :) –  user10319 Aug 24 '12 at 18:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.