This is my original idea (even before the Duplicate idea) simply using the GQL addTask()
mutation in Script to copy the all the Task details to a new Task Type.
I was having trouble getting this work last night, but today it is working!
I think it might be because yesterday I was using {CALL:X}
to execute the function, but today I am using the Execute Script
Action.
##TASK TYPE
Our new Task Type for Waiter Food Orders
##KD Waiter - Food (Task Type)##
Name: | KD Waiter - Food |
Custom Fields
(none)##SCRIPT
This script looks the same as previously posted, but one of the functions has been updated, so you need to update the Script functions. Specifically, the
addTask()
function has been updated.
##TSK Task Type Functions
[tasks]
(Script)##
Script Name: | TSK Task Type Functions |
Script Handler: | tasks |
Script:
function getTaskbyIdentifier(taskType,ident,field) {
// getTaskbyIdentifier('KD Task GUI - Food','27751-Qure Burger.Burger-12837-j9tXI2XMRkq7Q446SFfroQ')
taskType = typeof taskType==='undefined' ? '' : taskType;
ident = typeof ident==='undefined' ? '' : ident;
field = typeof field==='undefined' ? 'name' : field;
if (taskType=='' || ident=='') {
return false;
}
var qry = '{task:getTask(taskType:"'+taskType+'",identifier:"'+ident+'"){id,name,identifier,content}}';
var r = gql.Exec(qry);
r = JSON.parse(r);
var task = r.data.task;
//dlg.ShowMessage("tt:"+taskType+"\rid:"+ident+"\rname:"+task.name);
return task[field];
}
function addTask(taskType,name,content,ident,color,taskTypeOld) {
// addTask('KD Waiter - Food','','blah','27751-Qure Burger.Burger-12837-j9tXI2XMRkq7Q446SFfroQ','#FFFFFF00')
taskType = typeof taskType==='undefined' ? '' : taskType;
taskTypeOld = typeof taskTypeOld==='undefined' ? '' : taskTypeOld;
taskTypeOld = taskTypeOld=='' ? 'KD Task GUI - Food' : taskTypeOld;
ident = typeof ident==='undefined' ? '' : ident;
name = typeof name==='undefined' || name=='' ? getTaskbyIdentifier(taskTypeOld,ident,'name') : name;
color = typeof color==='undefined' ? '' : color;
var oldContent = getTaskbyIdentifier(taskTypeOld,ident,'content');
oldContent = oldContent.replace(/"/g,"'"); // replace double-quotes so they do not make GQL error
oldContent = oldContent.replace(/\r\n/g,'<br/>'); // replace linefeeds so they do not make GQL error
content = oldContent + '<br/>' + content;
//dlg.ShowMessage("tt:"+taskType+"\rid:"+ident+"\rname:"+name+"\rcontent:"+content);
if (taskType=='' || name=='') {
return false;
}
var qry='mutation m {addTask (task:{taskType:"'+taskType+'",name:"'+name+'",content:"'+content+'",isCompleted:false,identifier:"'+ident+'",customData:[{name:"Color",value:"'+color+'"}]}){id,name,isCompleted,content,identifier,customData{name,value}}}';
var r = gql.Exec(qry);
r = JSON.parse(r);
var task = r.data.addTask;
return task.name;
}
function updateTask(taskType,name,ident,color,complete,content) {
// updateTask('KD Waiter - Food','','27755-Poutine-12841-swifCxkYVk6UDrmcd0JUmg','#FFFFFF00')
taskType = typeof taskType==='undefined' ? '' : taskType;
ident = typeof ident==='undefined' ? '' : ident;
name = typeof name==='undefined' || name=='' ? getTaskbyIdentifier(taskType,ident,'name') : name;
color = typeof color==='undefined' ? '' : color;
complete = typeof complete==='undefined' || complete==''? false : true;
content = typeof content==='undefined' ? '' : content;
//dlg.ShowMessage("tt:"+taskType+"\rid:"+ident+"\rname:"+name+"\rcontent:"+content);
if (taskType=='' || name=='') {
return false;
}
var qry='mutation m {updateTask (taskType:"'+taskType+'",identifier:"'+ident+'",task:{taskType:"'+taskType+'",isCompleted:'+complete+',identifier:"'+ident+'",customData:[{name:"Color",value:"'+color+'"}]}){id,name,isCompleted,content,identifier,customData{name,value}}}';
var r = gql.Exec(qry);
r = JSON.parse(r);
var task = r.data.updateTask;
return task.name;
}
##ACTION
##KD ExecScript
[Execute Script]
(Action)##
Action Name: | KD ExecScript |
Action Type: | Execute Script |
Function: | [:handler.func] |
Command: | [:cmd] |
Run In Background: | [:runBG] |
##RULE
##KD Ready - Food
[Automation Command Executed]
(Rule)##
Rule Name: | KD Ready - Food |
Event Name: | Automation Command Executed |
Rule Tags: |
|
Execute Rule if: | Matches |
Automation Command Name | Equals | KD Ready - Food |
##Actions (1):##
KD ExecScript
Constraint: (none)
handler.func: | tasks.addTask('KD Waiter - Food','','XXXXX READY XXXXX','[:CommandValue]','#55007700','KD Task GUI - Food') |
cmd: | |
runBG: | |
##NOTES:
This function call:
tasks.addTask('KD Waiter - Food','','XXXXX READY XXXXX','[:CommandValue]','#55007700','KD Task GUI - Food')
Has 6 parameters:
addTask(taskTypeNew,taskName,content,identifier,color,taskTypeOld)
Maps out like this:
taskTypeNew = 'KD Waiter - Food' // our new Task Type for the Waiter Display
taskName = '' // optional, when left blank, it will use the same taskName as the KD Food Task
content = 'XXXXX READY XXXXX' // optional, content will be appended to the Order on the Waiter Task Card
identifier = '[:CommandValue]' // leave this alone, the value is passed as the [Id] for the KD Food Task Widget
color = '#55007700' // medium Green color
taskTypeOld = 'KD Task GUI - Food' // the original KD Food Task Type (ie. 'FoodDisplayTask')
#DEMO