Skip to content

Find one document

Find a unique document matching supplied query.

Returns document if one result found.

Returns null if no document found or multiple documents found.

Tip: If uniqueness is not known or guaranteed, use the findFirst method instead as it allows for multiple document matches to exist and hence is more flexible.

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();
Find a Formbird document
static final String KEY_SYSTEMHEADER_TEMPLATE_ID = "systemHeader.templateId";
static final String KEY_SYSTEMHEADER_SYSTEM_TYPE = "systemHeader.systemType";
static final String SYSTEM_TYPE_DOCUMENT = "document";
static final String TEMPLATE_ID_ASSET = "5ba9bbee5b116026f1b23dad";

String uniqueKey = "assetId";
String uniqueValue = "123";

String findQuery = "{\"query\":{\"bool\":{\"must\":["
    + " {\"term\":{\"" + uniqueKey + "\":\"" + uniqueValue + "\"}}"
    + ",{\"term\":{\"" + KEY_SYSTEMHEADER_TEMPLATE_ID + "\":\"" + TEMPLATE_ID_ASSET + "\"}}"
    + ",{\"term\":{\"" + KEY_SYSTEMHEADER_SYSTEM_TYPE + "\":\"" + SYSTEM_TYPE_DOCUMENT + "\"}}"
    + "]}}}";

// Find document
Document result = ftService.findOne(findQuery);

// Close ftService
ftService.close();