copy the description of a scrum task to another scrum task

santiago_bergal
Tera Expert

Hi! I'm working on a workflow where there is a story. The story has several scrum tasks and I need the description of the first scrum task to be copied with scripting to the description of the second scrum task. 

 

I'll be leaving a screenshot of the work flow and the code I have so far, which is not copying anything.

 

Thanks in advance!

 

var parent = current.sys_id;

task.parent = parent;


// Get the sys ID of the story
var storySysId = parent;

// Get the sys ID of the first and second tasks
var firstTask = new GlideRecord('rm_scrum_task');
firstTask.addQuery('story', storySysId);
firstTask.orderBy('sys_created_on');
firstTask.query();
if (firstTask.next()) {
var firstDescription = firstTask.description.toString();
}
var secondTask = new GlideRecord('rm_scrum_task');
secondTask.addQuery('story', storySysId);
secondTask.orderByDesc('sys_created_on');
secondTask.query();
if (secondTask.next()) {
secondTask.description = firstDescription;
secondTask.update();
}

6 REPLIES 6

Ratnakar7
Mega Sage
Mega Sage

Hi @santiago_bergal ,

 

Please try with below script:

 

var parent = current.sys_id;

task.parent = parent;

// Get the sys ID of the story
var storySysId = parent;

// Get the sys ID of the first and second tasks
var firstTask = new GlideRecord('rm_scrum_task');
firstTask.addQuery('story', storySysId);
firstTask.orderBy('sys_created_on');
firstTask.query();
if (firstTask.next()) {
  var firstDescription = firstTask.description.toString();
}

var secondTask = new GlideRecord('rm_scrum_task');
secondTask.addQuery('story', storySysId);
secondTask.orderByDesc('sys_created_on');
secondTask.query();
if (secondTask.next() && firstDescription) {
  secondTask.description = firstDescription;
  secondTask.update();
}

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

Ankur Bawiskar
Tera Patron
Tera Patron

@santiago_bergal 

update as this

var parent = current.sys_id;

task.parent = parent;


// Get the sys ID of the story
var storySysId = parent;
var firstDescription;
// Get the sys ID of the first and second tasks
var firstTask = new GlideRecord('rm_scrum_task');
firstTask.addQuery('story', storySysId);
firstTask.orderBy('sys_created_on');
firstTask.query();
if (firstTask.next()) {
	firstDescription = firstTask.description.toString();

	var secondTask = new GlideRecord('rm_scrum_task');
	secondTask.addQuery('story', storySysId);
	secondTask.orderByDesc('sys_created_on');
	secondTask.query();
	if (secondTask.next()) {
		secondTask.description = firstDescription;
		secondTask.update();
	}

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks @Ankur Bawiskar ! I'm afraid this is still not working. 

@santiago_bergal 

are you sure your query is getting the 1st task correctly?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader