1

I need to retrieve List item column values with column names on item click. In SP2010, I have a XSL which calls the JavaScript. I have sent the list item id through the XSL into the JavaScript function.

context = new SP.ClientContext.get_current();
list = context.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList());
pdfItem = list.getItemById(pdfItemID);  
context.load(pdfItem);
context.executeQueryAsync(
    function(sender, args) {
        currentItemGUID = pdfItem.get_item('UniqueId');
    },
    function(sender, args) {
        alert('Request Failed' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
    }, "sp.js");

pdfItem.get_schemaXml(); didn't work

2

You can get column/fields name from list unless they are not consistent and then use them to fetch values for each key, here's how you can get all fields for a list,

function loadFieldCustProperty() {
        var clientContext = new SP.ClientContext();
        var targetList = clientContext.get_web().get_lists().getByTitle('List Title');
        fieldCollection = targetList.get_fields();
        clientContext.load(fieldCollection);
        clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);


        function onQuerySucceeded() {

            var fe = fieldCollection.getEnumerator();
            while (fe.moveNext()) {
                var  field = fe.get_current();

                var xmlSchemaString = field.get_schemaXml();
                var fieldXml = parseXml(xmlSchemaString);
                var fieldElement = fieldXml.getElementsByTagName('Field')[0];
                var fieldPropertyValue = fieldElement.getAttribute('ColName'); //get ColName property value

                //...
            }

        }

        function onQueryFailed(sender, args) {
            //error handling goes here...
        }

    }

View custom field property value using JavaScript

Then, in here

currentItemGUID = pdfItem.get_item('UniqueId'); // here use field names e.g. using a enumerator for getting each column's value for selected item.

Also you might want to look at this question Javascript to get GUID from SharePoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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