+ Reply to Thread
Results 1 to 5 of 5
-
02-06-2008 12:27 AM #1Paayaa Guest
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
-
02-07-2008 11:55 AM #2
Administrator
- Join Date
- Mar 2007
- Posts
- 385
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);
-
02-07-2008 12:32 PM #3Paayaa Guest
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
-
02-07-2008 12:58 PM #4
Administrator
- Join Date
- Mar 2007
- Posts
- 385
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.
-
02-07-2008 01:32 PM #5Paayaa Guest
Thanks now it showed up.


LinkBack URL
About LinkBacks
Reply With Quote
