Skip to content

Create a document

Create a new Formbird document

Import Libraries
import org.apache.log4j.Logger;

import com.fieldtec.webclient.config.WebclientConfig;
import com.fieldtec.webclient.model.Document;
import com.fieldtec.webclient.service.FieldtecService;
import com.fieldtec.webclient.service.impl.FieldtecServiceImpl;
import com.fieldtec.webclient.util.UtilJson;
Setup the ftService
// Setup webclientConfig
WebclientConfig webclientConfig = WebclientConfig.getInstance();
webclientConfig.setAuthUrl(context.authUrl);
webclientConfig.setUsername(context.username);
webclientConfig.setPassword(context.password);
webclientConfig.setWebserviceUrl(context.webserviceUrl);

// Initialise ftService after setup of webclientConfig
FieldtecService ftService = new FieldtecServiceImpl();
Insert a Formbird document
static final String KEY_SYSTEMHEADER_TEMPLATE_ID = "systemHeader.templateId";
static final String TEMPLATE_ID_ASSET = "5ba9bbee5b116026f1b23dad";

// Construct a document, adding content and templateId
Document doc = new Document();
doc.setValue("assetId","123");
doc.setValue("name","asset name");
doc.setValue("description","asset description");
doc.setValue(KEY_SYSTEMHEADER_TEMPLATE_ID,TEMPLATE_ID_ASSET);

// Insert document
Document responseDocument = ftService.insert(doc);

// Close ftService
ftService.close();

if (responseDocument != null) {
    // Get documentId to return
    logger.info("Inserted: " + responseDocument.getValue(KEY_DOCUMENT_ID));
} else {
    // Handle error
    logger.error("Error inserting document");
}