You could use that function, but it returns a ProcessResult which would require figuring out how to work with that object. Also you would have to use the package path to the DWR and have an instance of the DWR. Instead, you should get the rt I was referring to the way I did,
function getMaintenanceEvent(xid) {
var id = com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao.instance.getIdByXid(xid);
if(id === null)
throw "Maintenance Event with XID:" + xid + " not found"
var rt = com.serotonin.m2m2.maintenanceEvents.RTMDefinition.instance.getRunningMaintenanceEvent(id);
if(rt === null)
return { "isEventActive": function() { return false }}; //disabled events considered inactive?
else
return rt;
}
and then your code could look like,
var maintEvt = getMaintenanceEvent("MNT_123");
if (maintEvt.isEventActive())
maintEvt.toggle();
Also the timing of the original question was inopportune as we added a script utility for Maintenance Events shortly after. It can be used like,
MaintenanceEventsUtility.isEventActive(xid); //requires maintenance events 3.5.1
MaintenanceEventsUtility.toggle(xid);
MaintenanceEventsUtility.setState(xid, boolean); //in 3.5.0 this happens even during validation
//in 3.5.0 the context name is maintenanceEventsUtility
It also has some CRUD functions exposed, which I would direct you to the code for: https://github.com/infiniteautomation/ma-modules-public/blob/main/Maintenance Events/src/com/infiniteautomation/mango/maintenanceEvents/MaintenanceEventsJavascriptUtility.java