How to check survey to finish and add that condition to workflow?

Enkhdalai
Tera Expert

Hello guys, 

 

I have a requested item and in stage 1 it creates catalog task. In the catalog task I have configured a survey.

 

In the requested item workflow I need to check surveys to finish and automatically close that task. 

 

Currently I added wait for condition after catalog task creation script and it stuck on the wait for condition. 

 

Here is my wait for condition script. 

 

// Set the variable 'answer' to true or false to indicate if the condition has been met or not.

//New employee first day questionnaire (Requester)
var metricType = 'd039d2d4db5c9d102439aa4dd39619bb';


var grInstance = new GlideRecord('asmt_assessment_instance');

grInstance.addQuery('trigger_id', current.sys_id);
grInstance.addQuery('metric_type', metricType);
grInstance.addQuery('state', 'complete');

grInstance.query();

if(grInstance.hasNext()){

answer = true;

}

else{

answer = false;

}

7 REPLIES 7

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

I believe the workflow is created on the RITM table, if yes then current.sys_id is the sysid of the RITM. You need to get the sysid of the catalog task for which the survey was created.

 

You can add the below line in your catalog task activity:-

 

workflow.scratchpad.variableName = task.sys_id;

 

And then it in your wait for condition:-

vasr sysid=workflow.scratchpad.variableName;

var metricType = 'd039d2d4db5c9d102439aa4dd39619bb';


var grInstance = new GlideRecord('asmt_assessment_instance');

grInstance.addQuery('trigger_id', sysid);
grInstance.addQuery('metric_type', metricType);
grInstance.addQuery('state', 'complete');

grInstance.query();

if(grInstance.hasNext()){

answer = true;

}

else{

answer = false;

}

Now you can use any other way as well to get the sysid of the catalog task

 

Please mark my answer as correct based on Impact.

Hi, Saurav11. 

 

I added workflow.scratchpad.variableName = task.sys_id; in catalog task activity. Please see below.

 

Enkhdalai_0-1668498195494.png

And in the wait for completion activity i have added below script.

 

var sysid=workflow.scratchpad.variableName;
var metricType = 'd039d2d4db5c9d102439aa4dd39619bb';
var grInstance = new GlideRecord('asmt_assessment_instance');

grInstance.addQuery('trigger_id', sysid);
grInstance.addQuery('metric_type', metricType);
grInstance.addQuery('state', 'complete');

grInstance.query();

if(grInstance.hasNext()){

answer = true;

}

else{

answer = false;

}

 

But it seems can not pass the wait for completion condition and stuck on this activity.

 

Did I miss something? I have already took the assessment which fulfills the "true" value.

Hello,

 

I am not sure if the task sysid is getting captured in it do one thing again assuming the the workflow is on RITM table change and only one task is getting created use the below in wait for condition:-

 

var metricType = 'd039d2d4db5c9d102439aa4dd39619bb';
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id)
gr.query();
if(gr.next())
{
var grInstance = new GlideRecord('asmt_assessment_instance');
grInstance.addQuery('trigger_id', gr.sys_id);
grInstance.addQuery('metric_type', metricType);
grInstance.addQuery('state', 'complete');
grInstance.query();
if(grInstance.hasNext()){
answer = true;
}
else{
answer = false;
}
}

 

Please mark my answer as correct based on Impact.

 

I have tried this script and still does not work. Workflow is still hanging on the wait for condition activity. I will keep the the record for additional solutions.