Skip to content

Update a document

Update an existing 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();
Update a Formbird document
static final String KEY_SYSTEMHEADER = "systemHeader";
static final String KEY__ID = "_id";

// Find a document to update
Document existingDocument = findAsset("123");

// Always remove systemHeader and _id before updating an existing document
existingDocument.remove(KEY_SYSTEMHEADER);
existingDocument.remove(KEY__ID);

// Apply updates to existing document
existingDocument.setValue("description", "asset description revised");

// Update document
Document responseDocument = ftService.update(existingDocument);

// Close ftService
ftService.close();

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