SPXmlToJson with variable

Feb 21, 2013 at 1:57 PM
I am attempting to use SPXmlToJson in conjunction with a GetListItems which worked great however; I am in need of allowing my function to dynamically pull from different lists based on a user input. Using global variables I am able to change mappedName and objectType. I am unable to use a variable for the name (ows_x) it doesn’t read the value but attempts to pull the variable name as the value. Any help would be appreciated I am relatively new to this so if it’s a simply error please forgive me.

var Json = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
mapping: {
 ows_ID: {mappedName: varX, objectType: varY}, //this works
 varA: {mappedName: varB, objectType: varC} //this does not
includeAllAttrs: true
removeOws: true
Feb 22, 2013 at 3:49 PM

I banged together this simple example. I think it should give you enough to go on.
        operation: "GetListItems",
        async: false,
        listName: "Announcements",
        CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
        completefunc: function (xData, Status) {
            var mappings = {};
            mappings.ows_ID = {mappedName: "ID", objectType: "Counter"};
            var colName = "ows_Title";
            mappings[colName] = {mappedName: 'Title', objectType: 'Text'};
            var Json = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({ 
                mapping: mappings,
                removeOws: true 
Feb 25, 2013 at 1:34 PM
Thank you that worked great for me.