+ Reply to Thread
Results 1 to 10 of 14
-
04-18-2008 12:35 PM #1toolbox Guest
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.
-
04-22-2008 10:00 AM #2
Administrator
- Join Date
- Mar 2007
- Location
- Prezza Technologies
- Posts
- 227
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.
-
04-24-2008 11:00 AM #3toolbox Guest
-
04-29-2008 03:01 PM #4toolbox Guest
Any luck creating the survey and/or creating the response on the fly? Any help with this will really be appreciated.
Thanks
-
04-30-2008 07:15 PM #5
Administrator
- Join Date
- Mar 2007
- Location
- Prezza Technologies
- Posts
- 227
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:
Next, you'll create an instance of a response and initialize it:Code:ResponseTemplate rt = ResponseTemplateManager.GetResponseTemplate(1234);
...to be continuedCode://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);
-
05-02-2008 12:00 PM #6toolbox Guest
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.
-
06-10-2009 06:47 PM #7
Junior Member
- Join Date
- Jun 2009
- Posts
- 3
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.
-
06-11-2009 11:46 AM #8
Administrator
- Join Date
- Mar 2007
- Posts
- 385
In the case of an anonymous respondent I believe the ExtendedPrincipal is null.
-
06-11-2009 11:54 AM #9
Junior Member
- Join Date
- Jun 2009
- Posts
- 3
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);
-
06-11-2009 12:30 PM #10
Administrator
- Join Date
- Mar 2007
- Posts
- 385
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());


LinkBack URL
About LinkBacks
Reply With Quote

