Hi team,
I've applied the JavaScript code to initiate the restart of my workflow. Despite confirming the real status and observing it as "finished," whenever the JavaScript activity is executed, it consistently displays "No event," despite the workflow already being in a finished state. Can someone clarify why this inconsistency is happening?
var query = xtk.queryDef.create(
<queryDef schema = {vars.targetSchema} operation = "select">
<select>
<node expr="@state"/>
</select>
</queryDef>
);
var record = query.ExecuteQuery();
var status = vars.state;
if (status=="Finished"){
xtk.workflow.Restart("workflowInternalName");
task.postEvent(task.transitionByName("Ok"));
}
else {
task.postEvent(task.transitionByName("No"));
}
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @AkshayAnand ,
Thank you for your response. I managed to resolve the issue by updating my JavaScript activity to below, and everything is functioning correctly now.
var query = xtk.queryDef.create(
<queryDef schema = {vars.targetSchema} operation = "select">
<select>
<node expr="@status"/>
<node expr="@state"/>
<node expr="@internalName"/>
</select>
</queryDef>
);
var workflowsToStart = query.ExecuteQuery();
var stats = vars.status;
for each (var variable in workflowsToStart) {
vars.workflowID = variable.@internalName;
if (stats=5){
xtk.workflow.Restart(vars.workflowID);
task.postEvent(task.transitionByName("Ok"));
}
else if(stats=13){
xtk.workflow.Restart(vars.workflowID);
task.postEvent(task.transitionByName("Ok"));
}
else {
task.postEvent(task.transitionByName("No"));
}
}
Views
Replies
Total Likes
Hi @rvnth
I hope you are referring the variable "Status" as the workflow state and your target schema is xtk:workflow. Hence could you kindly try using the below code.
var query = xtk.queryDef.create(
<queryDef schema = "xtk:workflow" operation = "select">
<select>
<node expr="@state"/>
</select>
<where>
<condition expr="[@internalName] = 'workflowInternalName'"/>
</where>
</queryDef>
);
var record = query.ExecuteQuery();
logInfo(record);
var status = record.@state;
if (status=="Finished"){
xtk.workflow.Restart("workflowInternalName");
task.postEvent(task.transitionByName("Ok"));
}
else {
task.postEvent(task.transitionByName("No"));
}
Regards
Akshay
Views
Replies
Total Likes
Hi @AkshayAnand ,
Thank you for your response. I managed to resolve the issue by updating my JavaScript activity to below, and everything is functioning correctly now.
var query = xtk.queryDef.create(
<queryDef schema = {vars.targetSchema} operation = "select">
<select>
<node expr="@status"/>
<node expr="@state"/>
<node expr="@internalName"/>
</select>
</queryDef>
);
var workflowsToStart = query.ExecuteQuery();
var stats = vars.status;
for each (var variable in workflowsToStart) {
vars.workflowID = variable.@internalName;
if (stats=5){
xtk.workflow.Restart(vars.workflowID);
task.postEvent(task.transitionByName("Ok"));
}
else if(stats=13){
xtk.workflow.Restart(vars.workflowID);
task.postEvent(task.transitionByName("Ok"));
}
else {
task.postEvent(task.transitionByName("No"));
}
}
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies