Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

 

The FAQs provide some examples and code snippets for common tasks when a third-party application wants to interact with the server.

On this page:

Table of Contents
maxLevel1

How do I login and logout to and from

...

a server?

See the Java code snippet below:

...

Code Block
    FormsService fs = ...;
    ApplicationEntry appEntry = ...; // find app entry
    FormTypeEntry ftEntry = ...; // find template form entry 
    ftEntry.setTitle(new PlainTextConstruct("MyForm"));
    ftEntry.setSummary(new PlainTextConstruct("MyForm Description"));
    FormTypeFeed ftFeed = appEntry.getFormTypeFeed();
    FormTypeEntry newEntry = ftFeed.insert(ftEntry);

How do I

...

copy a form?

It is also possible to download a form using the API similar to the way you can download one from the UI. Consider the following code snippet:Copying entails inserting an existing entry into a feed. The key difference between this case and a regular feed insert() is that the entry being inserted already has an id: this will trigger a copy.

Code Block
    FormsService// fsget = ...;
    ApplicationEntry appEntry = ...; // find app entry
    the FormTypeEntry you want to copy
    FormTypeEntry ftEntry = ...;
// find
template form entry  // get the FormTypeFeed MediaContentyou mcwill = (MediaContent) ftEntry.getContent();copy TO
    MediaSourceFormTypeFeed mstargetFeed = getService().getMedia(mc);appEntry.FormTypeFeed;

    // OutputStreamPerform formStreamthe =copy
new FileOutputStream("myform_form.zip");   FormTypeEntry  saveFormToDisk(ms.getInputStream(), formStream);copy = ftFeed.Insert(FormType);
Note

You can only insert into a feed that has an explicit owner, which is guaranteed above by getting the FormTypeFeed from the ApplicationEntry as opposed to getting a FormTypeFeed containing forms for all applications.

 

How do I

...

download an existing

...

form?

You can also upload It is also possible to download a form that was previously downloaded using the using the API similar to the way you can download one from the UI. Consider the following code snippet:

Code Block
    FormsService fs = ...;
    ApplicationEntry appEntry = ...; // find app entry
    FormTypeFeedFormTypeEntry ftFeedftEntry = appEntry...getFormTypeFeed(); // find template form InputStreamentry formZipStream
= new FileInputStream("myform_form.zip");  MediaContent mc  MediaStreamSource formMediaSource = new     MediaStreamSource(formZipStream,"application/zip"= (MediaContent) ftEntry.getContent();
    MediaSource ms = getService().getMedia(mc);
    FormTypeEntryOutputStream ftEntryformStream = ftFeed.insert(formMediaSource);

How do I use Self-signed Certificates with the API?

One approach is to modify the client code to accept self-signed certificates, but the recommended method is to use the standard Java mechanisms to trust a self-signed certificate; for example, to add the self-signed certificates to the JRE trusted keystore.

  • Use a key tool to create a key
  • Used installcert.java to install the certificate in a trusted keystore
  • Save the keystore in the ''jre-home\lib\security'' directory
  • Restart the server

How do I set a form's Deployment State?

Code Block
FormTypeEntry ftEntry = setUpFormType(appEntry);
try {
System.out.println("Default State: " + ftEntry.getDeployState());
ftEntry.setDeployState(DeployState.PRODUCTION);
ftEntry = ftEntry.update();
ftEntry = ftEntry.getSelf();
assertEquals("Should be PRODUCTION state", ftEntry.getDeployState(), DeployState.PRODUCTION);

ftEntry.setDeployState(DeployState.DEVELOPMENT);
ftEntry = ftEntry.update();
ftEntry = ftEntry.getSelf();
assertEquals("Should be DEVELOPMENT state", ftEntry.getDeployState(), DeployState.DEVELOPMENT);

FormTypeFeed ftFeed = appEntry.getFormTypeFeed();
FormTypeEntry newEntry = ftFeed.createEntry();
newEntry.setTitle(new PlainTextConstruct("MyForm123"));
newEntry.setSummary(new PlainTextConstruct("MyForm123 Description"));
newEntry.setVisibility(Visibility.PUBLICTENANT);
newEntry.setDeployState(DeployState.PRODUCTION);
newEntry = ftFeed.insert(newEntry);
assertNotNull(newEntry.getSelf());
assertEquals("Should be PRODUCTION state", newEntry.getDeployState(), DeployState.PRODUCTION);
newEntry.delete(); new FileOutputStream("myform_form.zip");
    saveFormToDisk(ms.getInputStream(), formStream);

How do I upload a form into an existing application?

You can also upload a form that was previously downloaded using the following code snippet:

Code Block
    FormsService fs = ...;
    ApplicationEntry appEntry = ...; // find app entry
    FormTypeFeed ftFeed = appEntry.getFormTypeFeed();
    InputStream formZipStream = new FileInputStream("myform_form.zip");
    MediaStreamSource formMediaSource = new     MediaStreamSource(formZipStream,"application/zip");
    FormTypeEntry ftEntry = ftFeed.insert(formMediaSource);

How do I use Self-signed Certificates with the API?

One approach is to modify the client code to accept self-signed certificates, but the recommended method is to use the standard Java mechanisms to trust a self-signed certificate; for example, to add the self-signed certificates to the JRE trusted keystore.

  • Use a key tool to create a key
  • Used installcert.java to install the certificate in a trusted keystore
  • Save the keystore in the ''jre-home\lib\security'' directory
  • Restart the server

How do I set a form's Deployment State?

Code Block
FormTypeEntry ftEntry = setUpFormType(appEntry);
try {
System.out.println("Default State: " + ftEntry.getDeployState());
ftEntry.setDeployState(DeployState.PRODUCTION);
ftEntry = ftEntry.update();
ftEntry = ftEntry.getSelf();
assertEquals("Should be PRODUCTION state", ftEntry.getDeployState(), DeployState.PRODUCTION);

ftEntry.setDeployState(DeployState.DEVELOPMENT);
ftEntry = ftEntry.update();
ftEntry = ftEntry.getSelf();
assertEquals("Should be DEVELOPMENT state", ftEntry.getDeployState(), DeployState.DEVELOPMENT);

FormTypeFeed ftFeed = appEntry.getFormTypeFeed();
FormTypeEntry newEntry = ftFeed.createEntry();
newEntry.setTitle(new PlainTextConstruct("MyForm123"));
newEntry.setSummary(new PlainTextConstruct("MyForm123 Description"));
newEntry.setVisibility(Visibility.PUBLICTENANT);
newEntry.setDeployState(DeployState.PRODUCTION);
newEntry = ftFeed.insert(newEntry);
assertNotNull(newEntry.getSelf());
assertEquals("Should be PRODUCTION state", newEntry.getDeployState(), DeployState.PRODUCTION);
newEntry.delete();

Why are deleted submissions showing up in the submissions feed?

The submissions feed will retrieve all type of submissions: submitted, saved, deleted (Deleted submissions are soft deleted meaning they are marked in the database as deleted, but the records are still present in the DB and they will be returned in the SubmissionFeed). The  Submissions UI page, by design, shows only the submissions which are completed.

Let's say you want to sort submissions that are saved versus those that are submitted. You can use the SubmissionEntry.getState() method. This will return the current state of a SubmissionEntry (SAVED or SUBMITTED). You can use this property to distinguish between your submissions.

How do I get a form submission PDF when Save PDF is not enabled?

Using API, you can instantiate each form submission, get the PDF for that instance and then cancel the form instance. Note that the PDF will not show up in the form submission when using this approach as the instance is canceled.

Here is an example API script that will download PDF's for all form submissions to disc:

Code Block
/ formTypeID of your form. You can get the formTypeId of a form by looking at its Share URL. For example, if your forms Raw URL is: http://localhost:8082/frevvo/web/tn/qa/user/fd/app/_S5QyQQ8GEeKoZPV3UpCRog/formtype/_W03sMA8GEeKoZPV3UpCRog?_method=post&embed=true&locale=, then the part of this URL between formtype/ and ?_method is your formTypeId.
String formTypeId = "_W03sMA8GEeKoZPV3UpCRog";  

// Get the Forms Service.
FormsService service = new FormsService("http", "localhost", 8082, null);
service.login("designer@tutorial", "designerpswd");

// Get Submission Feed
SubmissionQuery q = new SubmissionQuery(service.getFeedURL(SubmissionFeed.class));
q.setFilter("$formTypeId eq " + formTypeId);
q.setOrderby("$updated");  
SubmissionFeed sFeed = service.getFeed(q, SubmissionFeed.class);

int counter = 1;
// Download PDF for each submission
for (SubmissionEntry contact : sFeed.getEntries()) {
       // re-instantiate the form from the submission
       URL fUrl = contact.createFormInstance(null, null);
       // Construct the URL which will generate the PDF
       String pdfUrl = fUrl.toString() + "&print=true&format=pdf";
       String filename = "E:\\myFormPDF" + counter + ".PDF";
       BufferedInputStream in = null;
       FileOutputStream fout = null;
       try
       {
             in = new BufferedInputStream(new URL(pdfUrl).openStream());
             fout = new FileOutputStream(filename);

             byte data[] = new byte[1024];
             int count;
             while ((count = in.read(data, 0, 1024)) != -1)
             {
                    fout.write(data, 0, count);
             }
       }
       finally
       {
             if (in != null)
                    in.close();
             if (fout != null)
                    fout.close();
       }      
       counter ++;
       // Cancel the instance
       Helper.cancelInstance(service, fUrl);    
}