Hey there,
I'm having some trouble using the OKMNotification class in a script with the API.
Can somebody please give me an example of how to use the "notify" function correctly or tell me where I got my script wrong?
I especially got problems with the definition of "List<String> users":
If I try to set the users variable like so: "List<String> = {"okmAdmin"};" I get a Pars error: "Parse error at line XX, column YY. Encountered: ="
If I try to convert the variable from a simple String Array ("String[] users = {"okmAdmin"};") to a "List<String>" like so: "new List<String>(Arrays.asList(users))" I again get a Pars error: "Parse error at line XX, column YY. Encountered: <"
I've also tried converting it from a simple String Array ("String[] users = {"okmAdmin"};") to some similar Java data types which haven't worked either:
Converting the variable to a Array List with the String template like so: "new ArrayList<String>(Arrays.asList(users))" I again get a Pars error: "Parse error at line XX, column YY. Encountered: <"
If I try to convert the users variable to a ArrayList like so: "Arrays.asList(users)" I get a weird error: "Error: com.openkm.principal.PrincipalAdapterException: Can't send notification because 'from' or 'to' is empty"
I have following script:
I'm having some trouble using the OKMNotification class in a script with the API.
Can somebody please give me an example of how to use the "notify" function correctly or tell me where I got my script wrong?
I especially got problems with the definition of "List<String> users":
If I try to set the users variable like so: "List<String> = {"okmAdmin"};" I get a Pars error: "Parse error at line XX, column YY. Encountered: ="
If I try to convert the variable from a simple String Array ("String[] users = {"okmAdmin"};") to a "List<String>" like so: "new List<String>(Arrays.asList(users))" I again get a Pars error: "Parse error at line XX, column YY. Encountered: <"
I've also tried converting it from a simple String Array ("String[] users = {"okmAdmin"};") to some similar Java data types which haven't worked either:
Converting the variable to a Array List with the String template like so: "new ArrayList<String>(Arrays.asList(users))" I again get a Pars error: "Parse error at line XX, column YY. Encountered: <"
If I try to convert the users variable to a ArrayList like so: "Arrays.asList(users)" I get a weird error: "Error: com.openkm.principal.PrincipalAdapterException: Can't send notification because 'from' or 'to' is empty"
I have following script:
Code: Select all
import com.openkm.api.*;
import com.openkm.bean.*;
import com.openkm.dao.*;
import com.openkm.module.db.stuff.*;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import com.openkm.module.jcr.stuff.*;
try{
String token = DbSessionManager.getInstance().getSystemToken();
String nodePath = "";
List<String> users = {"okmAdmin"};
String msg = "A Notification";
boolean attachment = false;
OKMNotification.getInstance().notify(token, nodePath, users, msg, attachment);
} catch(Exception e) {
UserActivity.log("okmAdmin", "TCC_NOTIFICATION", null, null, "ERROR: " + e);
print("-> Error: " + e + "\n");
}