API basics & Customizing Tactic

How to get started with the API and begin customizing TACTIC

Examples from the Video

1 - Expressions

@GET(jobs/job.name)
@SOBJECT(jobs/job)
@COUNT(jobs/job.sthpw/task['status', 'Approved])

2 - Alert

//Show an Alert
alert("Tactic!");
spt.info("Tactic!");
spt.error("Tactice Error!");
spt.alert("Tactic Alert:<br><div>Content of the alert in html.</div>", {type: 'html'});

3 - Javascript Query

//Javascript - Query for Items
var server = TacticServerStub.get();
var expr = "@SOBJECT(jobs/job)";
var jobs = server.eval(expr);
console.log(jobs);

//Alternatively, you can use log.critical()

log.critical(jobs);

4 - Python Query

#Python  - Query for Items
server = TacticServerStub.get()
expr = "@SOBJECT(jobs/job)"
jobs = server.eval(expr)
server.log("info", jobs)

return jobs

5- Python Trigger

In the configuration page, add a python trigger to the insert event with the following code.

# Simple trigger to set the description of a new item
search_key = input.get("search_key")
data = {
    'description':  'Hey, I'm a new Job'
}
server.update(search_key, data)

Custom Widget

HTML

<h1>List of Jobs</h1>
<%
expr = "@GET(jobs/job.name)"
jobs = server.eval(expr)

context.write("<ul>")
for job in jobs:
    context.write("<li class='job-item'>%s</li>" %job)
context.write("</ul>")
%>

Styles

.job-item {
    font-size: 20px
}

 

 

Developer