Actionable task for Survey response.

Ram117
Kilo Sage

Hello Experts,

I have created a survey for Service Desk team. One of the question in the Survey is as below

find_real_file.png

 

Whenever the response is Yes, I want to create an actionable Task to the Service Desk managers , they get notified and can update & close the task . I am looking for some guidance what would be the best approach to do this ?

Thx

ram.

1 ACCEPTED SOLUTION

James Gragston
Tera Guru

ram,

Create an 'After' Business Rule on the [asmt_assessment_instance] table that runs when a record is updated. The condition should be as follows:

State | Changes to | Complete

You only want this BR to run when the user has completed the survey and has therefore populated the field you require to drive task creation. This table holds the survey state and should update the record when a survey is completed.

You'll need the sys_id of the 'current' record to query the [asmt_metric_result] table. This table holds not only the numeric value of the user's input but also the semantic (text) value of the input.

Since you know the specific question that drives task creation, you can hard-code this value. And since there are only two answers to this question, you can create an 'if' statement with the answer you're looking for.

(function executeRule(current, previous /*null when async*/ ) {

    var metrics = new GlideRecord('asmt_metric_result');
    metrics.addQuery('instance', current.sys_id);

    //hard-code the 'Metric' field value since this will not change
    //this value is the 'name' of the survey question so it should be unique
    metrics.addQuery('metric', '44934f181bc8805420748622dd4bcbbf');
    metrics.query();

    //returns one record since survey question names are unique
    if (!metrics.nil()) {

        var input = metrics.string_value;//value is 'yes' or 'no' depending on user input
        if (input == 'yes') {

            //fire event to trigger your notification
            //change the last two arguments to fit your requirements
            gs.eventQueue('my.registered.event', current, gs.getUserID(), gs.getUserName());
        }
    }

})(current, previous);

The above code does not include the task creation but that's easy enough to script. Just use the initialize() & insert() functions to create and save the new record and the setValue() function to set the task record values like the 'assigned_to' field. Register your event and configure your notification to have it fire when the event is triggered.

 

Hope this helped!

View solution in original post

3 REPLIES 3

James Gragston
Tera Guru

ram,

Create an 'After' Business Rule on the [asmt_assessment_instance] table that runs when a record is updated. The condition should be as follows:

State | Changes to | Complete

You only want this BR to run when the user has completed the survey and has therefore populated the field you require to drive task creation. This table holds the survey state and should update the record when a survey is completed.

You'll need the sys_id of the 'current' record to query the [asmt_metric_result] table. This table holds not only the numeric value of the user's input but also the semantic (text) value of the input.

Since you know the specific question that drives task creation, you can hard-code this value. And since there are only two answers to this question, you can create an 'if' statement with the answer you're looking for.

(function executeRule(current, previous /*null when async*/ ) {

    var metrics = new GlideRecord('asmt_metric_result');
    metrics.addQuery('instance', current.sys_id);

    //hard-code the 'Metric' field value since this will not change
    //this value is the 'name' of the survey question so it should be unique
    metrics.addQuery('metric', '44934f181bc8805420748622dd4bcbbf');
    metrics.query();

    //returns one record since survey question names are unique
    if (!metrics.nil()) {

        var input = metrics.string_value;//value is 'yes' or 'no' depending on user input
        if (input == 'yes') {

            //fire event to trigger your notification
            //change the last two arguments to fit your requirements
            gs.eventQueue('my.registered.event', current, gs.getUserID(), gs.getUserName());
        }
    }

})(current, previous);

The above code does not include the task creation but that's easy enough to script. Just use the initialize() & insert() functions to create and save the new record and the setValue() function to set the task record values like the 'assigned_to' field. Register your event and configure your notification to have it fire when the event is triggered.

 

Hope this helped!

Ram117
Kilo Sage

Thank you very much for the reply.

I understand the trigger conditions on assessment instance table. The question was mostly on the actionable task which I have to create. Can I just use the task table to achieve the creation of the actionable task ?

 

What I am hoping to have is,

Under Service Desk application 

Module called Survey Actionable Tasks

  1) Open Tasks

  2) Closed Tasks

  3) All Tasks

I am also assuming that, I will have to create custom UI actions inorder to achieve the closure & save actions on the task table..

Please correct if I am wrong in my thought process.

 

Thx

ram.

 

 

Ram117
Kilo Sage
(function executeRule(current, previous /*null when async*/) {
	
	// Add your code here
	if (previous.state != "complete" && current.state == "complete") {
		
		gs.log('user who is carrying out the survey is '+gs.getUserDisplayName());
		gs.log('value of the survey instance ID is '+current.sys_id);
		
		//Querying the metric result table and checking if the survyee has answered
		// the response as Yes for Manager Callback
		var grMetRes = new GlideRecord('asmt_metric_result');
		var qry = "instance.sys_idSTARTSWITH"+current.sys_id;
		grMetRes.addQuery(qry);
		grMetRes.addQuery('metric.sys_id','ebe0bd5fdb900810785ffd3339961917');
		grMetRes.query();
		if (grMetRes.next()) {
			
			var metResult = grMetRes.string_value;
			
			if (metResult == "Yes") {
				
				// initialize u_survey_fb_task() and create the task record
				
				var grTask = new GlideRecord('u_survey_fb_task');
				grTask.initialize();
				
				// populate the fields
				
				var pattern = /^Call: /i;
				// populate short and Description fields
				if (pattern.test(current.trigger_id.getDisplayValue())) {
					var callID = current.trigger_id.getDisplayValue().replace(/^Call: /i,"");
					grTask.short_description = "Customer requested a callback on survey record "+current.number+" related to "+callID ;
					
					var grMetRes1 = new GlideRecord('asmt_metric_result');
					grMetRes1.addQuery('instance.sys_id',current.sys_id);
					grMetRes1.addQuery('metric','ebe0bd5fdb900810785ffd3339961913');
					grMetRes1.query();
					if(grMetRes1.next())  {
						grTask.description  = "*** Below is the comment provided by Customer *** \n ";
						grTask.description += grMetRes1.string_value;	
					}
					
				}
					
				grTask.active = true;
				grTask.assignment_group = "cf8cc1c8db7a3f0063923df339961966"; // SYS_ID of Service Desk Escalation.
				grTask.u_assessment_instance = current.sys_id;
				var retID = grTask.insert();
				
				
			}
			
		}
		
		
	}
	
	
})(current, previous);

 

attached is the code, if any one would like to refer.