Absent Member.
Absent Member.

Can I duplicate a subtask linked to the parent?


I would like to duplicate a subtask and have it linked to the parent just like the subtask it copied.

What's the best approach?

Should I do a post and then have an appscript enter a row in the ts_subtasks table?


4 Replies
Absent Member.
Absent Member.


That seems like a good way to do it and probably the easiest if you know how to script it. The other option might be an orchestration and use the LinkSubtask web service. That one just requires that you know the id of the parent and child and will create the link for you.
Fleet Admiral
Fleet Admiral

From the parent can you repeat the "subtask" transition? This will initialize all the "housekeeping" references. Then use scripting to copy data fields from the first subtask to the second.
Absent Member.
Absent Member.

This is not as easy as I thought it would but. I found that the script I put on the post transition of my "Duplication Transition" was still reading the current record I was trying to duplicate.

To get past that problem I put the logic of the script on the Submit Transition that my duplication transition was targeting. That post transition action is able to pickup the new item ID of the duplicated subtask.

Now I'm trying to go back to the parent to read the TS_ID of the parent so I can complete my TS_SUBTASK row. I had been passing the Parent ISSUEID to the subtasks so I thought I would use that information to query the parent table. I just can't seem to get the value.

Here's a subset of my code:

Call current.GetFieldValue("PARENT_ISSUE_ID",parent_issue_id_var) 'from a field on the subtask

if duplicated_item_var = 1 Then
End If

sub Duplication Sub
set parent_list = Ext.CreateAppRecordList(Ext.TableID("USR_PARENT")) 'Create a record containing all subtasks from the parent table.
sqlWhereClause2=" TS_ISSUEID = "& parent_issue_id_var & ""

If parent_list.ReadwithWhere(sqlWhereClause2) then
For each item in parent_list
call item.GetFieldValue("ACTIVEINACTIVE",active_inactive_status_var)
call item.GetFieldValue("ID",parent_item_id_var)

if active_inactive_status_var = "1" Then
Shell.RedoMessage="You can not create a Duplicate subtask if the Parent is closed. br>"
End if
Shell.RedoMessage="There was an error with the where clause " & sqlWhereClause2 & "
End if

Set messageRecord = ext.CreateAppRecord(ext.TableId("TS_SUBTASKS"))
Call messageRecord.SetFieldValue("SUBTABLEID",sub_table_id)
Call messageRecord.SetFieldValue("SUBITEMID",current_subtask_ID)
Call messageRecord.SetFieldValue("MASTERTABLEID",main_table_ID)
Call messageRecord.SetFieldValue("MASTERITEMID",parent_item_id_var)
Call messageRecord.SetFieldValue("PROGRESS",0)

Call messageRecord.Add()

End Sub 'Duplication Sub

And the result is: Unable to find item 0 in table PARENT during GetMasterItemAndState.

Ran this sql through toad and received the right result... Why isn't it working in my appscript code?

where USR_PARENT.TS_ISSUEID = '2127'

Maybe I just need to read current ID on the parent and pass that forward, that should work... Just pile on another field..... would be nice if this code would work.

Any suggestions welcome.

Absent Member.
Absent Member.

I took the easy approach and read the current shell parent item and passed that value through the post transition.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.