Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


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:

 

Code Block
\"action\":\"getcondition\", 

 

is

...

always

...

followed

...

by

...

the

...

following:

...

Code Block
\"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:

Code Block
\"action\":\"getcondition\", \"filter\":\"\" 

...

If

...

you'd

...

prefer

...

to

...

have

...

no

...

records

...

returned,

...

use

...

the

...

following:

...

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

...

 

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

Code Block
<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>

...

Code Block
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\" } ]";
	}
}