...answers when you need them
866-430-8274    1-617-715-9605
  • Free Version
  • Contact Us
  • Login

Checkbox Forums

Register | Help
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    toolbox Guest

    Default Create New Survey/Response via API

    If I link to the following in our site(site and querystring values have been removed),
    http://oursite.com/Survey.aspx?v1=17...ame&v4=company &v5=other data&v6=20

    it will create a new response record for the given survey, saving the querystring values as hidden fields. Is it possible to do the same thing with the API from our application and get the new response id?

    Also, is it possible to create a new survey with several default questions added and get the new survey id?

    thanks in advance.

  2. #2
    ncushing is offline Administrator
    Join Date
    Mar 2007
    Location
    Prezza Technologies
    Posts
    207

    Default

    All of this is definitely possible. For your first question, the steps would be to create a new response, then read the query string values to add the "answers" to the hidden items.

    Prepopulating a survey would be a little more work, but still doable. I'll put together some sample code and reply to this post in a little bit.

  3. #3
    toolbox Guest

    Default

    Quote Originally Posted by ncushing View Post
    All of this is definitely possible. For your first question, the steps would be to create a new response, then read the query string values to add the "answers" to the hidden items.

    Prepopulating a survey would be a little more work, but still doable. I'll put together some sample code and reply to this post in a little bit.
    Could I also get a little help with creating the response, and adding the hidden item values? I haven't been able to find much to help me with that in the documentation, and am not having much luck getting my response, etc created.

    Thanks.

  4. #4
    toolbox Guest

    Default

    Any luck creating the survey and/or creating the response on the fly? Any help with this will really be appreciated.

    Thanks

  5. #5
    ncushing is offline Administrator
    Join Date
    Mar 2007
    Location
    Prezza Technologies
    Posts
    207

    Default

    Sorry for the delay...we've been busy working on getting 4.5 out the door.

    To create a response, you'll first need to load the response template:

    Code:
    ResponseTemplate rt = ResponseTemplateManager.GetResponseTemplate(1234);
    Next, you'll create an instance of a response and initialize it:

    Code:
    //Create a response object
    Response response = rt.CreateResponse("en-US");
    
    //Initialize the new response
    ExtendedPrincipal respondent = (ExtendedPrincipal)UserManager.GetCurrentPrincipal();
    string userIp = "198.168.0.1";
    string userNTLoginName = string.Empty;
    
    //Initialize is done only one time per response
    response.Initialize(userIp, userNTLoginName, "en-US", respondent);
    
    //After initialize, the response ID and GUID are available
    Guid responseGuid = response.GUID;
    long responseId = response.ID;
    
    //To load an existing response:
    ResponseTemplate rt = ResponseTemplateManager.GetResponseTemplate(1234);
    
    Response response = rt.CreateResponse("en-US");
    response.Restore(responseGuid);
    ...to be continued

  6. #6
    toolbox Guest

    Default

    Ok, so I have figured out how to do a lot of the survey creation, but am still having a few problems. Here is what i have so far:

    //create the response template
    ResponseTemplate rt = ResponseTemplateManager.CreateResponseTemplate(Use rManager.AuthenticateUser(un,pw));
    rt.Name = txtname.Text;
    rt.IsActive = true;
    rt.EditLanguage = "EN-us";
    rt.Title = txtname.Text;
    rt.SupportedLanguages = new string[] { "en-US" };
    rt.DefaultLanguage = "en-US";
    rt.EnableDynamicItemNumbers = true;
    rt.EnableDynamicPageNumbers = true;
    rt.CompletionType = 1;
    rt.ShowTitle = true;
    rt.ShowProgressBar = true;
    rt.StyleTemplateID = 1015;
    rt.AllowContinue = true;
    rt.ShowPageNumbers = true;
    rt.Save();
    //add a template page for the hidden items
    TemplatePage page = rt.NewPage(0);

    //for each hidden item do the following
    //create the hidden item
    HiddenItemData hid = (HiddenItemData)ItemConfigurationManager.CreateCon figurationData(12);
    hid.VariableName = VariableName;
    hid.VariableSource = HiddenVariableSource.QueryString;
    hid.Alias = Alias;
    hid.Save();
    //add the item to the page:
    rt.AddItemToPage(page, hid);

    So all this seems to be working, but i have found two steps i cannot figure out how to do using the API. I have gotten them to work if I call stored procedures I found in the DB, and I would rather not do it that way.
    1. How do i move the response template to a currently existing folder in our DB?
    2. How do I set the text of the hidden item, so it appears when viewing results for the survey in the checkboxweb app?

    Thanks for the help on this so far.

  7. #7
    cregan is offline Junior Member
    Join Date
    Jun 2009
    Posts
    3

    Default

    Is there a way to similarly generate a new response for an anonymous user? I was able to get the provided sample code working for an autheniticated user but would like to create a response and retrieve the associated guid for an anonymous respondent.

    Thanks.

  8. #8
    pwiesner is offline Administrator
    Join Date
    Mar 2007
    Posts
    382

    Default

    In the case of an anonymous respondent I believe the ExtendedPrincipal is null.

  9. #9
    cregan is offline Junior Member
    Join Date
    Jun 2009
    Posts
    3

    Default

    Thanks for the reply. We have tried passing in null for the ExtendedPrincipal, but the Initialize call throws a NullReferenceException.

    ResponseTemplate rt = ResponseTemplateManager.GetResponseTemplate(1030);
    //Create a response object
    Response response = rt.CreateResponse("en-US");

    //Initialize the new response
    //ExtendedPrincipal respondent = (ExtendedPrincipal)UserManager.AuthenticateUser("user", "password");

    ExtendedPrincipal respondent = null;
    string userIp = "198.168.0.1";
    string userNTLoginName = string.Empty;

    //Initialize is done only one time per response
    response.Initialize(userIp, userNTLoginName, "en-US", false, respondent);

  10. #10
    pwiesner is offline Administrator
    Join Date
    Mar 2007
    Posts
    382

    Default

    Sorry about that. I thought ResponseController automatically instantiated an AnonymousRespondent when the principal was null. You should be able to manually instantiate an AnonymousRespondent, which extends the ExtendedPrincipal class, and use that.


    AnonymousRespondent respondent = new AnonymousRespondent(new Guid());

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Feedback

SEO by vBSEO 3.5.0