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
Guest
 
Posts: n/a
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
Senior Member
 
Join Date: Mar 2007
Posts: 194
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
Guest
 
Posts: n/a
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
Senior Member
 
Join Date: Mar 2007
Posts: 194
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
Guest
 
Posts: n/a
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

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


All times are GMT -5. The time now is 02:57 AM.


SEO by vBSEO 3.2.0