Java Example --Recursive Queries - Documentation for Remedy Action Request System 18.05

private static final String EMPLOYEE_FORM = "Employee";
private static final int EMP_EMPLOYEE_NAME = 536870913;
private static final int EMP_EMPLOYEE_ID = 536870914;
private static final int EMP_MANAGER_ID = 536870915;
private static final int EMP_MANAGER_ID = 536870915;
private void queryOnEmployeeForm(ARServerUser arConnection) throws ARException
{
	// Create recursive query part first.
	RecursiveQuery recursive = new RecursiveQuery();
	
	// Add Employee form as the source. Since there is only
	// one source you do not need to specify recursive source with
	// the setRecursiveForm method.
	QuerySourceForm employeeForm = new QuerySourceForm(EMPLOYEE_FORM);
	recursive.addFromSource(employeeForm);
	
	// The following fields are included in the results of the recursion.
	recursive.addFromField(EMP_EMPLOYEE_NAME, employeeForm);
	recursive.addFromField(EMP_EMPLOYEE_ID, employeeForm);
	recursive.addFromField(EMP_MANAGER_ID, employeeForm);
	
	// Create the starting qualifier.
	ArithmeticOrRelationalOperand startFieldOp = 
    new ArithmeticOrRelationalOperand(EMP_EMPLOYEE_NAME, employeeForm);
	ArithmeticOrRelationalOperand startValueOp = 
    new ArithmeticOrRelationalOperand(new Value("Bob Jones"));
	RelationalOperationInfo startRelOp = 
    new RelationalOperationInfo(RelationalOperationInfo.AR_REL_OP_EQUAL, 
    startFieldOp, startValueOp);
	QualifierInfo startQual = new QualifierInfo(startRelOp);
	recursive.setQualifier(startQual);
	
	// Create the recursion qualifier.
	ArithmeticOrRelationalOperand recurseField1 = 
    new ArithmeticOrRelationalOperand(EMP_MANAGER_ID, employeeForm);
	ArithmeticOrRelationalOperand recurseField2 = 
    new ArithmeticOrRelationalOperand(EMP_EMPLOYEE_ID, recursive);
	RelationalOperationInfo recurseRelOp = 
    new RelationalOperationInfo(RelationalOperationInfo.AR_REL_OP_EQUAL, 
    recurseField1, recurseField2);
	QualifierInfo recurseQual = new QualifierInfo(recurseRelOp);
	recursive.setRecursionQualifier(recurseQual);
	
	// Specify the number of levels in the hierarchy to retrieve.
	// Specify 3 to retrieve 2 levels below the parent level.
	// (The parent level is identified by the starting qualifier.)
	recursive.setLevelsToRetrieve(3);
	
	// Create regular query.
	RegularQuery query = new RegularQuery();
	
	// Add recursive query as source.
	query.addFromSource(recursive);
	
	// Add the fields from the recursive query as the return field
	// in the regular query.
	query.addFromField(EMP_EMPLOYEE_NAME, recursive);
	query.addFromField(EMP_EMPLOYEE_ID, recursive);
	query.addFromField(EMP_MANAGER_ID, recursive);
	
	// Call routine.
	List<QuerySourceValues> results = 
    arConnection.getListEntryObjects(query, 0, 0, false, null);
}
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest