Find first document
Find first document matching supplied query.
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.findFirst(findQuery);
// Close ftService
ftService.close();