Survey Software by Prezza Technologies - survey software, web surveys, online surveys, online survey, customer feedback forms, survey hosting

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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-06-2008, 12:27 AM
Paayaa Paayaa is offline
Junior Member
 
Join Date: Jan 2008
Posts: 7
Post Copy Survey as new survey using API

Hi there,
Below is a senario I am trying to achive using API. I tought I post it in community so that if I get responses all member can use it later on :

Here is What I want to do (all with CheckBox API only) if anyone did this before please help me.

I have couple of surveys that I use them as template to create new surveys
here are the steps I want to implement :

1- List the surveys located under a folder to user (see "Get Survey ID under a folder" as how to do that
Thank to ncushing)

2- User will pick one of the survey and click on create survey

3- My application use the ResponseTemplateID of selected Survey and copy survey as a new Survey
Question : probably should use ResponseTemplateManager.CopyResponseTemplate(....) but I don't know what parameters I should pass e.g. IAccessPermissabl?? or LanguageCode?

4- After I have the new Survey (assuming I will have the ResponseTemplateID of new survey), I like to add users to the survey and later send them invitation.

Thanks
Paayaa
Reply With Quote
  #2 (permalink)  
Old 02-07-2008, 11:55 AM
pwiesner pwiesner is offline
Senior Member
 
Join Date: Mar 2007
Posts: 125
Default

Most of the Checkbox API methods take an IAccessPermissible object as a parameter; it is used to gate access. The following code example demonstrates how to obtain an ExtendedPrincipal object, which is a concrete implementation of the IAccessPermissible interface, and the current users default language.

Code:
ExtendedPrincipal currentPrincipal = (ExtendedPrincipal)UserManager.GetCurrentPrincipal();
string language =  WebTextManager.GetUserLanguage();

ResponseTemplate newSurvey = ResponseTemplateManager.CopyTemplate(templateId, currentPrincipal, language);
Reply With Quote
  #3 (permalink)  
Old 02-07-2008, 12:32 PM
Paayaa Paayaa is offline
Junior Member
 
Join Date: Jan 2008
Posts: 7
Default copied but don't show it in checkbox

Thanks for reply,

One issue and one question. I start with the issue :

I use admin account that have full access right and here is the code I use to to copy a survey as a new survey (assuming I know the TemplateID)

public static ResponseTemplate CreateNewPoll(int pollTemplateID)
{
//Initialize the user manager, only needs to be done once per IIS Application lifetime.
UserManager.Initialize();
string[] adminRoles = { "System Administrator" };
IIdentity adminID = UserManager.GetUserIdentity("admin");
ExtendedPrincipal adminPrincipal = new ExtendedPrincipal(adminID, adminRoles);

string language = WebTextManager.GetUserLanguage();

ResponseTemplate newPoll = ResponseTemplateManager.CopyTemplate(pollTemplateI D, adminPrincipal, language);
return newPoll;

}

It will create the survey but when I login to checkbox using admin username, password I can not see the survey. I checked the database and I can see it added a row to ckbx_ResponseTemplateTable. What am I missing?

Question : If I want to create this new survey under a folder which function(s) I should use?

Thanks again
Reply With Quote
  #4 (permalink)  
Old 02-07-2008, 12:58 PM
pwiesner pwiesner is offline
Senior Member
 
Join Date: Mar 2007
Posts: 125
Default

I apologize my original response was incomplete. The new survey needs to be added to a folder, be it the root or a sub folder, in order to be visible in the application.

private void MoveSurveyToFolder(ResponseTemplate survey, int folderId)
{
if (folderId == 0)
{
FormFolder folder = FormFolder.GetRoot();
folder.Add(survey);
}
else
{
FormFolder folder = new FormFolder();
folder.Load(FolderID);

folder.Add(survey);
}
}

Where folderId is the id of the sub folder you would like to add the survey too.
Reply With Quote
  #5 (permalink)  
Old 02-07-2008, 01:32 PM
Paayaa Paayaa is offline
Junior Member
 
Join Date: Jan 2008
Posts: 7
Default

Thanks now it showed up.
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

vB 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 09:47 PM.


Search Engine Friendly URLs by vBSEO 3.0.0 RC8