Live Forms v5.1 is no longer supported. Click here for information about upgrading to our latest GA Release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 24 Next »

On this page:

How do I login/logout to/from a Form server?

The direct method for an existing user: See the C# code snipped below:

          FormsService service = new FormsService("http://localhost:8082", "yourappname");
          service.Login("myuser", "mypassword");
          UserEntry user = service.GetUser(“myuser”); 
                   
          // interact with frevvo
                   
          service.Logout();

Note that when you login, the .NET client API initializes a local security token based on your credentials.  It does not actually make a call however, until you make your first request.  At that time, the forms service will attempt to authorize you based on your token.  In the above example, the first call is for the user entry.

The LoginAs method for an existing user:

This new method allows you to login as any of the existing tenant users provided you can pass in the tenant's admin user and password. This is quite convenient when you want login using the same user that is logged into your application without having to know their password.

IDictionary<string, string> customParams = new Dictionary<string, string>();
       customParams.Add("autoLogin", "true");


FormsService service = new FormsService("http://localhost:8082", "yourappname"); 
          service.LoginAs( 
          "myuser", 
          "tenantAdminUserName@myTenantName", 
          "tenantAdminPassword",
          false,
          null, null, null, null,
          customParams);

UserEntry user = service.GetUser(“myuser”); 
     
          //   interact with frevvo   
  
service.Logout(); 

 

How do I get the list of all applications for the current user?

    FormsService service = ...;
    ApplicationQuery query = service.CreateApplicationQuery(null);
    ApplicationFeed apps = service.Query(query);
    foreach (ApplicationEntry app in apps.Entries)
    {
            Console.WriteLine("App: " + app.Title.Text);
            // ...
    }

How do I get the list of all themes for the current user?

    FormsService service = ...;
    ThemeQuery query = service.CreateThemeQuery(null);
    ThemeFeed themes = service.Query(query);
    foreach (ThemeEntry theme in themes.Entries)
    {
            Console.WriteLine("Theme: " + theme.Title.Text);
    }

How do I get the list of all forms for the current user?

    FormsService service = ...;
    FormTypeQuery query = service.CreateFormTypeQuery(null);
    FormTypeFeed themes = service.Query(query);
    foreach (ThemeEntry formType in formTypes.Entries)
    {
            Console.WriteLine("Form Type: " + formType.Title.Text);
    }

How do I get the list of all forms for a given application?

The code snippet below prints the name of all forms in the appEntry application:

    ApplicationEntry app = ...; // find the right application
    FormTypeFeed formTypes = app.FormTypeFeed;
    foreach(FormTypeEntry formType in formTypes.Entries)
    {
        Console.WriteLine("Form Type: " + formType.Title.Text);
    }

How do I get the list of all schemas for the current user?

    SchemaQuery query = service.CreateSchemaQuery(null);
    SchemaFeed schemas = service.Query(query);
    foreach (SchemaEntry schema in schemas.Entries)
    {
        Console.WriteLine("Schema: " + schema.Title.Text);
    }

How do I get the list of all schemas for a given application?

The code snippet below prints the name of all schemas in the appEntry application:

    ApplicationEntry app = ...; // find the right application
    SchemaFeed schemas = app.SchemaFeed;
    foreach (SchemaEntry schema in schemas.Entries)
    {
        Console.WriteLine("Schema: " + schema.Title.Text);
    }

How do I create an Application?

    FormsService fs = ....;
    ApplicationQuery query = fs.CreateApplicationQuery(null);
    ApplicationFeed apps = fs.Query(query);
    ApplicationEntry app = apps.CreateEntry();
    app.Title.Text = "My First App";
    app = apps.Insert(app);

How do I find an existing Application?

At this point you have to manually filter the entries in an ApplicationFeed. See the following snippet:

    FormsService fs = ....;
    ApplicationQuery query = fs.CreateApplicationQuery(null);
    ApplicationFeed apps = fs.Query(query);
    foreach(ApplicationEntry app in apps.Entries) 
    {
        if( app.Title.Text == "My First App" )
            return app.Id.Uri;
    }

How do I delete an Application?

ApplicationEntry app = ...; // find the right application 
 
app.Delete();

 

How do I upload an Application for a specific user?

First get a hold of the corresponding UserEntry for the desired user, and then use the users ApplicationFeed.

string fileName = ....;
UserEntry user = ....;
 
MediaFileSource source = new MediaFileSource(fileName, 
ApplicationFeed.MEDIA_SOURCE_TYPE);
 
ApplicationFeed apps = user.ApplicationFeed;
ApplicationEntry app = apps.CreateEntry();
 
app.MediaSource = source;
app = apps.Insert(app);

How do I upload an Application?

string fileName = ....;
string appName = ....;
FormsService formsService = ....;
 
MediaFileSource source = new MediaFileSource(fileName, 
ApplicationFeed.MEDIA_SOURCE_TYPE);
 
ApplicationQuery query = formsService.CreateApplicationQuery(null);
ApplicationFeed apps = formsService.Query(query);
ApplicationEntry app = apps.CreateEntry();
app.Title.Text = appName;
app.MediaSource = source;
app = apps.Insert(app);

How do I download an Application?

FormsService formsService = ....;          
ApplicationEntry entry = ....;          
string fileName = ....;          
 
Stream contentStream = formsService.QueryContent(entry.Content);   
 
//if the Application needs to be written to a file:
using (FileStream fileStream = File.Create(fileName))
{
    contentStream.CopyTo(fileStream); 
} 

  

After I found a ApplicationEntry for the first time can I get the entry directly?

If you have an entry id you can retrieve the entry directly.

    string appId = ...;
    FormsService fs = ....;
    ApplicationEntry app = fs.GetApplication(appId);

How do I get the url to a form so it can be embedded in my HTML pages?

First get a hold of the corresponding FormTypeEntry, then get the form url as shown in the snipped below:

    FormTypeEntry formType = ...; // find the correct formtype entry
    string formTypeUrl = formType.FormTypeEmbedLink.AbsoluteUri;

Then using the url in formTypeUrl above you can generate the following script tag in your html page:

<script type="text/javascript" src="{formTypeUrl}"></script>

This will embed the form in your page inside an <iframe/>.

How do I get the url to the form designer so it can be embedded in my HTML pages?

First get a hold of the corresponding FormTypeEntry, then get the formType url as shown in the snipped below:

    FormTypeEntry formType = ...; // find the correct formtype entry
    string designerUrl = formType.FormTypeEditorEmbedLink.AbsoluteUri;

Then using the designerUr' above you can generate the following script tag in your html page:

<script type="text/javascript" src="{designerUrl}"></script>

This will embed the form designer in your page inside an <iframe/>.

How do I get the url to the form submissions so it can be embedded in my HTML pages?

First get a hold of the corresponding FormTypeEntry, then get the form url as shown in the snipped below:

    FormTypeEntry formType = ...; // find the correct formtype entry
    string formSubmissionsUrl = formType.SubmissionsEmbedLink.AbsoluteUri;

Then using the formSubmissionsUrl above you can generate the following script tag in your html page:

<script type="text/javascript" src="{formSubmissionsUrl}"></script>

This will embed the submissions view in your page inside an <iframe/>.

How do I get the url to the form instance so it can be embedded in my HTML pages?

First get a hold of the corresponding FormTypeEntry, then get the form instance url as shown in the snippet below:

FormTypeEntry formType = ....;
NameValueCollection nvc = null;
 
Uri formInstanceUri = formType.CreateFormInstance(nvc);
 
string formInstanceUrl = formInstanceUri.AbsoluteUri;

Then using the formInstanceUrl above you can generate the following script tag in your html page:

<script type="text/javascript"   src="{formInstanceUrl}"></script>

This will embed the form instance in your page inside an <iframe/>. 

How do I get a form entry based on a known id?

This is often needed when you need to relate a  form with another concept your application (e.g. you application has the concept of a report that has an associated  form). In this case you will store the form id somewhere and when needed fetch the form entry to embed it in your page, delete it, etc.
Here is how you get the for a form entry (in fact any entry):

    FormTypeEntry formType = ...; // find an entry
    string formTypeId = formType.Id.Uri;

Here you can associate the formtype id with your application objects and retrieve the corresponding entry at any time as follows:

    string formtypeId = "....";
    FormTypeEntry formtype = service.GetFormType(formtypeId);

How do I delete a form (or any other entry)?

By calling the delete method on the FormTypeEnty.

    FormTypeEntry formType = ...;
    formType.Delete;

How do I create a new form?

First you have to get a hold of the form feed from an existing application. See How do I get the list of all forms for a given application?.

    FormsService service = ...;
    ApplicationEntry app = ...; // find an application
    FormTypeFeed formtypes = app.FormTypeFeed;
    FormTypeEntry formtype = formtypes.CreateEntry();
    formtype.Title.Text = name;
    formtype.Summary.Text = description;
    formtype = formtypes.Insert(formtype);

When inserting the original formtype variable will not' be updated and the updated entry will be returned by the Insert method.

How do I create a new form using an existing one as a template?

The only difference between creating a new form and creating a new one based on an existing form is that instead of using the entry created by calling 'ftFeed.createEntry()' you will be using an existing form entry. Find an existing form entry, update its name and description and use that entry to insert into a feed. Do not override the entry id otherwise the insert will fail.

    FormsService service = ...;
    ApplicationEntry app = ...; // find an application
    FormTypeFeed formtypes = app.FormTypeFeed;
    FormTypeEntry template = ...; // find template formtype entry
    // modify key template properties
    template.Title.Text = name;
    template.Summary.Text = description;
    FormTypeEntry formtype = formtypes.Insert(template);

How do I create a form instance?

 Use the code below to create a form instance: 

FormsService service = ...; 

string id = "_LIAtYHC3EeKVINiYeE5iPA!_qrSmgInoEeKOdqjLR19yFQ!test1"; 
FormTypeEntry formType = service.GetFormType(id); 
FormEntry form = formType.CreateFormEntry(); 

 

How do I pre-populate values when creating an instance?

When creating a form instance, you can supply data to pre-populate fields.  There are a couple of ways to do this.  The first way is to supply a name value collection, which holds control names and values.  The second way is to supply an XML document, with control names and values. Suppose your form has two text fields, named A and B respectively.  Also, suppose you wish to prefill these 2 controls with values, as shown:

Example 1 – using a name value collection

 This example uses a special parameter named _data.  The value carries a formatted string containing the form values, as shown below.

FormsService service = ...; 

NameValueCollection nvc = new NameValueCollection(); 
nvc.Add("_data", "{A:TestA,B:TestB}");

string id = "_LIAtYHC3EeKVINiYeE5iPA!_qrSmgInoEeKOdqjLR19yFQ!test1"; 
FormTypeEntry formType = service.GetFormType(id);
FormEntry form = formType.CreateFormEntry(nvc); 

Example 2 – using an XML document

This example uses an XML document.  The document structure contains the form values which are to be applied, as shown below.

<ns:form xmlns:ns="http://www.frevvo.com/schemas/_lvxDAF_vEd2bxNL8keLevQ" 
         name="FormTypeAtomTest">
   <A>TestA</A>
   <B>TestB</B>
</ns:form> 

FormsService service = ...;

using (FileStream docStream = File.Open(@"C:\temp\_data.xml", FileMode.Open))
{
       string id = "_LIAtYHC3EeKVINiYeE5iPA!_qrSmgInoEeKOdqjLR19yFQ!test1"; 
       FormTypeEntry formType = service.GetFormType(id);
       FormEntry form = formType.CreateFormEntry(docStream);
} 

How do I edit a form control?

Suppose you have a form with controls named A and B.  Further, suppose the form is initially empty, and you wish to programmatically set the control values to TestA and TestB respectively.  First you have to get a hold of the form instance (see 'How do I create a form instance?).

FormEntry form = ...;

ControlEntry controlA = form.FindControlEntry("A");
controlA.Value = "TestA";
ControlEntry controlB = form.FindControlEntry("B");
controlB.Value = "TestB";  

How do I submit a form?

First you have to get a hold of the form instance (see 'How do I create a form instance?). When you are finished editing your form, you may submit it as follows:

FormEntry form = ...; 
SubmissionEntry submission = form.Submit(); 

How can I print a submission as PDF (if no snapshot was saved)?

First you have to get a hold of the form instance (see 'How do I create a form instance?).

FormEntry form = ...;
SubmissionEntry submission = form.Submit(); 
using (Stream file = File.OpenWrite("C:\temp"))
{
submission.PrintFormInstance(file);
}

How can I save a form for working on later?

First you have to get a hold of the form instance (see 'How do I create a form instance?).

FormEntry form = ...; 
form.Save(); 

How can I resume working on a form I saved earlier?

Suppose you saved a form as in the above example.  Now, suppose you want to resume working on the form.  When you save a form, it becomes available for retrieval via the task feed.

string userName = "someUserName";
FormsService service = ...;

UserEntry userEntry =
service.GetUser(userName);

//NOTE: there may be multiple
entries in the TaskFeed list.  The last
entry in the list is the most recently added item. 
TaskEntry taskEntry = userEntry.TaskFeed.Entries[0] as TaskEntry;  

FormEntry form =
taskEntry.CreateFormInstance(); 

How do I upload an XSD Schema?

You can upload XSD schemas using the following code. Note that if the xsd being uploaded consists of multiple files you must upload the dependencies one by one making sure you start with the one without any dependencies, i.e. only upload schemas when all its dependencies are already uploaded.

    // Need an application to upload a schema
    ApplicationEntry app = ....;

    // create a mediasource to the xsd file
    string fileName = "\path\to\myschema.xsd";
    MediaFileSource source = new MediaFileSource (fileName, SchemaFeed.MEDIA_SOURCE_TYPE);

    // create a SchemaEntry 
    SchemaFeed schemas = app.SchemaFeed;
    SchemaEntry newSchema = schemas.CreateEntry ();

    // set the entry's media source
    newSchema.MediaSource = source;

    // perform the upload
    newSchema = schemas.Insert (newSchema);

How do I query the DocumentType's for a SchemaEntry?

You can list all the DocumentType's contained in a SchemaEntry by using the following code. Why would you want to do that? You use Schema DocumentType's to add to FormType's so controls can be auto-generated from it.

    SchemaEntry schema = ....; // got the schema somehow (maybe uploaded, maybe you    queried the existing schemas)
    DocumentTypeFeed docTypes = schema.DocumentTypeFeed;
    foreach( DocumentTypeEntry docType in docTypes.Entries )
    {
        Console.WriteLine(docType);
    }

How do I add a Schema DocumentType to a FormType?

Let's say I have a purchase order xsd and would like to auto generate a form for it. Let's say that I already uploaded the xsd and have a SchemaEntry at hand.

    ApplicationEntry app = ...; //
    SchemaEntry schema = ... ; // go the schemaentry somehow
    DocumentTypeFeed xsdDocTypes = schema.DocumentTypeFeed;
    DocumentTypeEntry xsdDocType = null;
    foreach(DocumentTypeEntry current in xsdDocTypes.Entries)
    {
        if( current.Title.Text == "http://myschema.com#purchaseorder" )
            srcDocType = current;
    }

    // create an empty form
    FormTypeFeed fts = app.FormTypeFeed;
    FormTypeEntry ft = fts.CreateEntry();
    ft.Title.Text = "My Purchase Order Form";
    ft = fts.Insert(ft);

    // Create a FormType DocumentTypeEntry based on the xsd one
    DocumentTypeFeed ftDocTypes = ft.DocumentTypeFeed;
    DocumentTypeEntry ftDocType = ftDocTypes.CreateEntry(xsdDocType);

    // add the schema DocumentType to the form
    ftDocType = ftDocTypes.Insert(ftDocType);

Now you have a new form named My Purchase Order Form and you have the purchase order element added to the Data Source pane in the Designer. Using the designer, expand the Data Source pane and click the plus button to auto-generate the form controls (note that the API will be expanded to support auto generating controls).

I added a DocumentType from a Schema to my FormType why do I see two DocumentType's?

Every FormType always has 1 default DocumentType that cannot be removed. This is the DocumentType managed by  and updated when controls from the palette are added or removed from the form. For this DocumentType the Delete() method will fail (you can check whether a DocumentType can be deleted or not using the entry's ReadOnly property).

How do I delete a FormType DocumentType that was added from Schema?

The following code will remove all FormType DocumentTypes that were added from Schema:

    FormTypeEntry ft = ...;
    DocumentTypeFeed docTypes = ft.DocumentTypeFeed;
    foreach(DocumentTypeEntry docType in docTypes.Entries )
    {
        if( !docType.ReadOnly )
            docType.Delete(); // not read-only so this must be from schema
    }

How do I set a form's Deployment State?

    FormTypeEntry ft = ...;
    ft.DeployState = DeployState.Production;
    // or
    ft.DeployState = DeployState.Development;

How to copy a form?

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.

    FormTypeEntry entry = ...;
    
    FormTypeFeed targetFeed = ...;
    FormTypeEntry copy = targetFeed.CreateEntry(); 
    copy.Id = entry.Id; 
    copy.Title.Text = "My copy"; 
    copy = targetFeed.Insert(copy); 

 

 

 

  • No labels