Need help with a script to copy values in a field (glide_list)

Sergio26
Giga Guru

Hello,

I'm trying to create a script so I can copy certain values from a table X into a field of type glide_list in another table. Here are the details.

From the table 'resource_plan' I want to retrieve each 'User resource' value and copy it in the field 'Additional assigne' of the corresponding 'Task'.

For example:

find_real_file.png

find_real_file.png

 

Ideally I don't want to push more than once the same User resource in a corresponding Task.

Thank you

 

 

1 ACCEPTED SOLUTION

Sergio26
Giga Guru

Hello,

I didn't have time to reply before but I was able to create a script from a couple of posts including some of the ones mentionned here.

Still I was missing the part where the elements pushed in the array had to be copied in a glide list of another table. So here is my final script.

var rpQuery1 = 'u_tache_principale.active=true';
//var rpQuery2 = 'number=prjtask0107247';
var taskList = [];

var taskGR = new GlideRecord(table);
taskGR.addEncodedQuery(rpQuery1);
//taskGR.addEncodedQuery(rpQuery2);
taskGR.query();
gs.print('Task Count: ' + taskGR.getRowCount());
while(taskGR.next()) {
	
	gs.print('Task ID: ' + taskGR.sys_id);
	taskList.push(taskGR.sys_id.toString());
	
}

gs.print('Task List: ' + taskList);

for(var i=0; i<taskList.length; i++ ) {
	
	gs.print('Task ID: ' + taskList[i]);
	
	var userList = [];
	var arrayUtil = new ArrayUtil();
	
	var resPlan = new GlideRecord('resource_plan');
	resPlan.addQuery('task', taskList[i]);
	resPlan.addEncodedQuery('user_resourceNSAMEAStask.assigned_to');
	resPlan.query();
	gs.print('Count: ' + resPlan.getRowCount());
	while(resPlan.next()) {
		
		if(arrayUtil.contains(userList,resPlan.user_resource.sys_id.toString())) {
			continue;
		}
		
		userList.push(resPlan.user_resource.sys_id);
		
	}
	
	gs.print('User list: ' + userList);
	
	var getTask = new GlideRecord('task');
	getTask.get('sys_id', taskList[i]);
	gs.print('Task ID: ' + getTask.sys_id);
	getTask.additional_assignee_list = userList.join(',');
	getTask.update();
	
}

 

Thank you all for your time and inputs.

View solution in original post

5 REPLIES 5

Sergio26
Giga Guru

Hello,

I didn't have time to reply before but I was able to create a script from a couple of posts including some of the ones mentionned here.

Still I was missing the part where the elements pushed in the array had to be copied in a glide list of another table. So here is my final script.

var rpQuery1 = 'u_tache_principale.active=true';
//var rpQuery2 = 'number=prjtask0107247';
var taskList = [];

var taskGR = new GlideRecord(table);
taskGR.addEncodedQuery(rpQuery1);
//taskGR.addEncodedQuery(rpQuery2);
taskGR.query();
gs.print('Task Count: ' + taskGR.getRowCount());
while(taskGR.next()) {
	
	gs.print('Task ID: ' + taskGR.sys_id);
	taskList.push(taskGR.sys_id.toString());
	
}

gs.print('Task List: ' + taskList);

for(var i=0; i<taskList.length; i++ ) {
	
	gs.print('Task ID: ' + taskList[i]);
	
	var userList = [];
	var arrayUtil = new ArrayUtil();
	
	var resPlan = new GlideRecord('resource_plan');
	resPlan.addQuery('task', taskList[i]);
	resPlan.addEncodedQuery('user_resourceNSAMEAStask.assigned_to');
	resPlan.query();
	gs.print('Count: ' + resPlan.getRowCount());
	while(resPlan.next()) {
		
		if(arrayUtil.contains(userList,resPlan.user_resource.sys_id.toString())) {
			continue;
		}
		
		userList.push(resPlan.user_resource.sys_id);
		
	}
	
	gs.print('User list: ' + userList);
	
	var getTask = new GlideRecord('task');
	getTask.get('sys_id', taskList[i]);
	gs.print('Task ID: ' + getTask.sys_id);
	getTask.additional_assignee_list = userList.join(',');
	getTask.update();
	
}

 

Thank you all for your time and inputs.