The list schema for survey list is quite different from the custom lists. Every question is added as the list column(field) and every response to questions is added as list item. To retrieve the survey question and and to submit the response to list via client object model, do the following. 1)Load the reference of sp.js and Load the address of function to be called as below SP.SOD.executeOrDelayUntilScriptLoaded(DisplaySurveyQ,’SP.js’); 2)Define the function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
var surveyItems = null; var surveyFields=null; var surveyList = null; var oneField = null; function DisplaySurveyQ() { var context = new SP.ClientContext.get_current(); var web = context.get_web(); // of your desired target list: surveyList = web.get_lists().getByTitle('surveylistName'); //alert(surveyList); var caml = new SP.CamlQuery(); surveyItems = surveyList.getItems(caml); surveyFields=surveyList.get_fields(); oneField = surveyFields.getByInternalNameOrTitle("Title"); //alert(surveyFields); //alert(surveyItems); //listOperations context.load(oneField); context.load(surveyList); context.load(this.surveyItems); context.load(this.surveyFields); context.load(list); alert(list); |
3) Create callback handlers in this function
|
var success = Function.createDelegate(this, this.onSuccess); var failure = Function.createDelegate(this, this.onFailure); |
4)Execute an async…