JSON getCondition Action

The getCondition action is a JSON action that you can use in one of the following places:

  • In a Field Condition input box - For example, you can use getCondition when using Reference fields. The user must choose a record from a list of parents, such as, choose an address to create a call.
  • When configuring a Quick Selector filter of type Toggle.


In both cases, you use getCondition to select which records to display to the user. getCondition is essentially the JSON equivalent of the fieldsOnConditionQuery or conditionQuery JavaScript statements.
Because getCondition displays a list to the user, it must have a filter key defined. You can define static filters or use IF statements to create conditional filters. Note that the following:

 

\"action\":\"getcondition\",

 

is always followed by the following:

\"filter\":\

 

 

In the following example code, getCondition is invoked when the CALREF1 field (Contact) from the activity is selected. If the CALREF2 field (Account) contains data, then Contacts (module 2) related to that account are displayed. If no Account is selected, then the ELSE statement returns all records using the following:

\"action\":\"getcondition\", \"filter\":\"\" 

If you'd prefer to have no records returned, use the following:

\"action\":\"getcondition\", \"filter\":\"1=2\"

 

The below example does mimic the default behavior of SwiftMEAP - to display all contacts related to an account.

<html><head><title>GetConditionExample</title><scripttype="text/javascript"> 
function conditionQueryJSON(){
	return "[{\"action\":\"select\",\"invoke\":\"getConditionQuery\",\"parameters\":[{\"modulefields\": [ { \"module\":\"6\",\"fields\":\"CALREF2\"} ], \"filter\":\"\",\"isfromscreen\":\"yes\"} ] } ]";
}
function getConditionQuery(row){
	if (row[0]._6.CALREF2){
		return "[ {\"action\":\"getcondition\",\"filter\":\"2.uid in (select childid from me_datarelation where parenttype=1 and childtype=2 and ( parentid="row[0]._6.CALREF2" or devicerowidparent="row[0]._6.CALREF2" ) ) \" } ]";
	}else{
		return "[ {\"action\":\"getcondition\",\"filter\":\"\" } ]";
	}
} 
function onErrorInvoke(rows){ 
	if(rows.length > 0){
		window.location="melt://showAlert/"+ rows[0].message;
	}
}
</script></head><body></body></html>


A more realistic example might be as below: Display all Contacts whose Job Title is CEO -

function conditionQueryJSON(){
	return "[{\"action\":\"select\",\"invoke\":\"getConditionQuery\",\"parameters\":[{\"modulefields\": [ { \"module\":\"6\", \"fields\":\"CALREF2\"} ], \"filter\":\"\",\"isfromscreen\":\"yes\"} ] } ]";
}
function getConditionQuery(row){
	if (row[0]._6.CALREF2){
		/** list the account's contacts which have job title of CEO**/
		return "[ {\"action\":\"getcondition\",\"filter\":\"2.CONTREF1="row[0]._6.CALREF2" and 2.CONTJOBTITLE=CEO\" } ]";
	}else{
		/** list all the contacts who have the job title of CEO**/
		return "[ {\"action\":\"getcondition\",\"filter\":\"2.CONTJOBTITLE=CEO\" } ]";
	}
}