SPServices/Json - "Requested Unknown Parameter" Missing JSON Column
SPServices/Json - "Requested Unknown Parameter" Missing JSON Column
Ben_Coding
Posts: 4Questions: 0Answers: 0
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?
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?
This discussion has been closed.
Replies
Allan
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!
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]
Allan