How to set a task's parent task?

Brian Bouchard
Mega Sage

I have a record producer script that is supposed to create a parent task in table TASKA, and children tasks in table TASKB.  The process is working as expected, except the child tasks are not properly related to the parent task.  Meaning if I go into a child task, the parent field is empty.  i've tried several iterations of code to get this working, but I'm clearly missing something obvious.

My code is as follows:

//set the array to parse through based on what was in the list collector
var arr = producer.access_level.toString().split(',');

var taskCount = arr.length;
gs.sleep(1000);
gs.log("ask count: " +taskCount,"rolemaint");


//create parent ticket & assign counters for # of child tasks for tracking
var parent = new GlideRecord("u_role_maint_parent");
parent.initialize();
parent.short_description="Request to Maintain Role " +producer.u_role +" submitted by " +gs.getUserDisplayName();
parent.u_child_task_count = taskCount;
parent.u_active_child_count = taskCount;
parentNum=parent.insert();



//Debugging Parent Assignment issues.
gs.sleep(1000);
gs.log('DEBUG PARENT NUM: ' + parentNum, "rolemaint");


//set current record producer to the 1st item in the array
current.u_access_level = arr[0];
current.parent=parentNum;

//for all the remaining items in the array, create a new task
for (var i=1; i<arr.length; i++) {
	gs.sleep(1000);
	gs.log('DEBUG LOOPING = ' + arr[i], "rolemaint");
	var gr = new GlideRecord('u_role_maint');
	gr.initialize();
	gr.u_role = producer.u_role;
	gr.u_access_level = arr[i];
	gr.u_action=producer.u_action;
	gr.parent=parentNum;
	gr.insert();
}

 

In the current iteration, parentNum  is assigned the sys_id of the parent task that was inserted, but the gr.parent=parentNum line is not setting it like I was expecting...

How can I get the gr.parent field properly set to the parent task record?

1 ACCEPTED SOLUTION

Once again, after struggling with this for several hours/days, I managed to find the answer to my question minutes after posting to the community.  Ahh the power of the community!

The issue was I had not set the reference on the child table to the table I wanted as the parent. The parent reference was defaulting to the Task table.  What was throwing me off was I was able to set the value manually through the form to any task, regardless of which table it was on.  Once I set the reference to point to the correct table, my code started working.

Thanks for your help and time, dinseh91n. I appreciate the effort to help me.

View solution in original post

4 REPLIES 4

dinesh91n
Tera Expert

Hi Brian,

Can you replace the line gr.parent = parentNum to gr.parent = parentNum.sys_id;

That didn't seem to work either.

Can you try again with the below line

gr.parent = parent.sys_id;

 

where parent.sys_id is the sys_id of the parent glideobject 

Once again, after struggling with this for several hours/days, I managed to find the answer to my question minutes after posting to the community.  Ahh the power of the community!

The issue was I had not set the reference on the child table to the table I wanted as the parent. The parent reference was defaulting to the Task table.  What was throwing me off was I was able to set the value manually through the form to any task, regardless of which table it was on.  Once I set the reference to point to the correct table, my code started working.

Thanks for your help and time, dinseh91n. I appreciate the effort to help me.