Go Back   CHECKBOX® Online Community > Checkbox® > CHECKBOX® Developer Kit

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2008, 11:35 AM
Junior Member
 
Join Date: Mar 2008
Posts: 14
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.
Reply With Quote
  #2 (permalink)  
Old 04-22-2008, 09:00 AM
Administrator
 
Join Date: Mar 2007
Location: Prezza Technologies
Posts: 187
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.
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 10:00 AM
Junior Member
 
Join Date: Mar 2008
Posts: 14
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.
Reply With Quote
  #4 (permalink)  
Old 04-29-2008, 02:01 PM
Junior Member
 
Join Date: Mar 2008
Posts: 14
Default

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

Thanks
Reply With Quote
  #5 (permalink)  
Old 04-30-2008, 06:15 PM
Administrator
 
Join Date: Mar 2007
Location: Prezza Technologies
Posts: 187
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
Reply With Quote
  #6 (permalink)  
Old 05-02-2008, 11:00 AM
Junior Member
 
Join Date: Mar 2008
Posts: 14
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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 04:27 AM.


SEO by vBSEO 3.2.0