...answers when you need them
866-430-8274    1-617-715-9605
  • Free Version
  • Contact Us
  • Login

Checkbox Forums

Register | Help
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Paayaa Guest

    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

  2. #2
    pwiesner is offline Administrator
    Join Date
    Mar 2007
    Posts
    382

    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);

  3. #3
    Paayaa Guest

    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

  4. #4
    pwiesner is offline Administrator
    Join Date
    Mar 2007
    Posts
    382

    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.

  5. #5
    Paayaa Guest

    Default

    Thanks now it showed up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Feedback

SEO by vBSEO 3.5.0