SPServices/Json - "Requested Unknown Parameter" Missing JSON Column

SPServices/Json - "Requested Unknown Parameter" Missing JSON Column

Ben_CodingBen_Coding Posts: 4Questions: 0Answers: 0
edited April 2013 in General
My JSON Code sometimes skips columns, due to the Source tables not being filled out completely. Null fields aren't returned in my web service.
SPservices only brings back the columns that are not null.

myJavascript:

[code] $().SPServices({
operation: "GetListItems",
async: false,
webUrl: "http://mywebsite.com",
listName: listA, //EDIT HERE// This is the Name of the Sharepoint List you want to Retrieve
completefunc: function (xData, Status) {

myJson = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
mapping: {
ows_LinkFilename: { mappedName: "Filename", objectType: "Text" },
ows_Title: { mappedName: "Title", objectType: "Text" },
ows_Unit_x0020_NO: { mappedName: "UnitNo", objectType: "Lookup" },
ows_Area: { mappedName: "Area", objectType: "Lookup" },
ows_Complex: { mappedName: "Complex", objectType: "Lookup" },
ows_DocType: { mappedName: "DocType", objectType: "Lookup" }
}, // name, mappedName, objectType
includeAllAttrs: false
});
//alert(myJson[0]["Title"]);//returns the value
return myJson

}// End of completefunc
}); //End of SPServices
[/code]

Console Info:
[quote]Row1 Debug: Object {Filename: "Test Folder", Title: "Test Folder"}
Row2 Debug: Object {Filename: "007316.pdf", Title: "7V-316", UnitNo: Object, Area: Object, Complex: Object…}[/quote]

What are my options?
Does the data have to be absolutely consistent each time?
I'm doing a webservices request for XML, tranforming to JSON and then posting to Datatables.
Can I turn off the debug... and just skip the Datatables Error message.

Or should I go back to my original webservice and see If I can change SPservices? What's the best practice or proper approach on this?

Replies

  • mrentropymrentropy Posts: 3Questions: 0Answers: 0
    Was this question ever solved? I'd be really interested in using SharePoint as a data source for DataTable, too.
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Please link to a test case or use the debugger: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
  • mrentropymrentropy Posts: 3Questions: 0Answers: 0
    My apologies, Allan. I hadn't progressed far enough to provide an example -- I'm trying to convert a static table (produced by a Data View Web Part in SharePoint and then formatted with DataTables) to something more dynamic (it's taking a really long time to load). I think what I'm envisioning may be too difficult anyway (from the SharePoint side, not DataTables).

    Note: since I'm giving up on being dynamic, I think this thread will solve my problem. I am just having trouble with speed, as it's a lot of information.

    http://datatables.net/forums/discussion/3541/javascript-array-spservices-does-not-match-known-number-of-columns/p1

    Thanks for writing such a terrific plugin!
  • Ben_CodingBen_Coding Posts: 4Questions: 0Answers: 0
    edited September 2013
    I was able to get it working yes.
    SPservices + Datatables.net works great!

    The solution:
    I used Allan's "sDefault":"" as a null or empty string
    and I defined each column that was to be displayed. This way datatables has a value for each object in the JSON dataset.

    Sharepoint by default doesn't return a value in the dataset if the cell or column is empty.
    So if a list with a column let's say named "comments" is empty, sharepoint doesn't return a value in the SPservices call/Webservice call. This creates a problem, at least from what I noticed with datatables which wants a value..

    I think it actually works quite fast... especially in IE10, and Chrome.
    IE8 has a bit of sluggish performance on larger datasets 1,000+.

    sample:
    [code]
    // See Reference: http://datatables.net/ref

    //Data Settings
    "aaData": null, //Pass Return XML/Json Data Here
    "bAutoWidth": false,

    "sDom":"ft",

    //Show Entries Drop-down Length Menu
    "iDisplayLength": -1,

    //Set Columns
    "aoColumnDefs": [{
    "mData": "Area.lookupValue",
    "sDefaultContent": "",
    "aTargets": [0]
    }, {
    "mData": "Complex.lookupValue",
    "sDefaultContent": "",
    "aTargets": [1]
    }, {
    "mData": "Unit",
    "sDefaultContent": "",
    "aTargets": [3],
    "sWidth": "50%"
    }, {
    "mData": "UnitShort",
    "sDefaultContent": "",
    "aTargets": [2]
    }

    ],
    //Data Speed Settings
    "bSortClasses": false, //Sort On Startup
    "bDeferRender": true //This speeds up Load, so IE doesn't have script error
    }
    [/code]

    My code is located at:
    [quote]https://gist.github.com/BenCoding/93f57cac7e08f2f9721e#file-datatables-htm[/quote]
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    @Ben_Coding: Awesome! Thanks for sharing your code with us!

    Allan
  • Ben_CodingBen_Coding Posts: 4Questions: 0Answers: 0
    Glad to help.
  • mrentropymrentropy Posts: 3Questions: 0Answers: 0
    @Ben_Coding: Thank you so much -- very much appreciated!
This discussion has been closed.