locked
What properties are needed when using the Object model to write to a survey? RRS feed

  • Question

  • using the object model to write to a survy.  Does anybody know what properties I need to use to set the default choice on a question? Set the question to required?

     

    objSurvey.Fields.Add(SplitEntries[0],

     

    SPFieldType.Choice, true, false, strQuestions);
     

    Many Thanks.


    • Edited by Mike Walsh FIN Monday, April 18, 2011 5:46 PM Title changed to a single question rather than a three section double question
    Monday, April 18, 2011 5:26 PM

Answers

  • Try this. 

     SPFieldChoice chFld = (SPFieldChoice)lst.Fields["StrQuestions"];

     chFld.EditFormat = SPChoiceFormatType.RadioButtons;

      chFld.DefaultValue = "Choice A";

     chFld.Update(); 

     objSurvey.Update();

    Thanks
    V
     




    V
    • Marked as answer by o365spo Wednesday, April 20, 2011 3:54 PM
    Monday, April 18, 2011 5:53 PM
  • Can you paste the whole code here? 

    you can set it to required by doing the following. 

    chdFld.Required = true;

     

    Thanks

    V


    V
    • Marked as answer by o365spo Wednesday, April 20, 2011 3:54 PM
    Monday, April 18, 2011 8:06 PM

All replies

  • Try this. 

     SPFieldChoice chFld = (SPFieldChoice)lst.Fields["StrQuestions"];

     chFld.EditFormat = SPChoiceFormatType.RadioButtons;

      chFld.DefaultValue = "Choice A";

     chFld.Update(); 

     objSurvey.Update();

    Thanks
    V
     




    V
    • Marked as answer by o365spo Wednesday, April 20, 2011 3:54 PM
    Monday, April 18, 2011 5:53 PM
  • I'm missing something here.. it's a survey. what's 1st? it did not like that.

    SPFieldChoice chFld = (SPFieldChoice)lst.Fields["strQuestions"];

    in my code strQuestions is an array with all the possible answers. 

    Also, how do I set the question to required programatically?

    Monday, April 18, 2011 7:43 PM
  • Can you paste the whole code here? 

    you can set it to required by doing the following. 

    chdFld.Required = true;

     

    Thanks

    V


    V
    • Marked as answer by o365spo Wednesday, April 20, 2011 3:54 PM
    Monday, April 18, 2011 8:06 PM
  •  I think I got it Thank you. The only thing I'm wondering about is what happens if I were to submit the same survey question twice  with the same name, will that identifier be wrong? How does it know which one to set the default for?

    objSurvey.Fields.Add("somequestion", SPFieldType.Choice, true, false, strQuestions);

    SPFieldChoice

    chFld = (SPFieldChoice)mySurvey.Fields["somequestion"];

    chFld.DefaultValue=strQuestions[0];

    Monday, April 18, 2011 8:53 PM
  • You can disallow multiple responses in the survey list. If you select A the first time, and choose to allow multiple responses, and Choose B or C, A will be available anymore. 

    Hope this helps.

    Thanks 

    V


    V
    Monday, April 18, 2011 9:00 PM
  • sorry, this code has nothing to do with the UI. It's creating a survey programatically. just wondering if If sharePoint lets me create the same question twice as that code is pulling the question, but the question text.

     

     


    Monday, April 18, 2011 10:03 PM
  • Yes. It does let you create the questions twice. 

     

    Thanks

    V


    V
    Tuesday, April 19, 2011 1:55 AM
  • got it working with this.. Thanks!
    Wednesday, April 20, 2011 3:54 PM