Highlighted
forumadmin Absent Member.
Absent Member.
11764 views

TeamScript - how to enumerate list, build new list, and update item with new list?


Question posted 8/26/08 by Mark Eliason
Details:

I have two item types (completely generic for the purposes of this example) – 1) Parent 2) Child. A Child is submitted from the Parent via a post transition. Post options in the Parent's workflow look like this:

Set New Item in This Item's Field : Linked Children (multi relational field)
Set This Item in New Item's Field : Parent Item (single relational field)

I'm looking for a script sample that would let me do this during certain transitions in the Child's workflow:

Get the id of the Child item going through the transition
Get the Parent Item value from the Child.
Get the list of Linked Children from the Parent
Enumerate the list of Linked Children
Build a new list of Linked Children, excluding the id of the Child going through the transition
Update the parent with the new list.


I think this is fairly straightforward, but I'm not too fluent in TeamScript yet. I'll be trying to piece this together, but if anybody has a working model of something similar I'd love to have a look...

Thanks a lot ˜
Mark

0 Likes
2 Replies
forumadmin Absent Member.
Absent Member.

Re: TeamScript - how to enumerate list, build new list, and update item with new list?


Comment posted 9/2/08 by a zonderman

Hi Mark,
Here's a model. Could be made more robust, but should give you the basic syntax for how to create & manipulate an AppRecord from a relational field.
Good luck,
Ariela
Const strRelToParent_DBName = "DBNAME_WITHOUT_TS"
Const strRelToChildren_DBName = "DBNAME_WITHOUT_TS"
'* Read value from the current item's single-relational field
Set fldRelToParent_Obj = Shell.Item.Fields().FindField(strRelToParent_DBName)
Call fldRelToParent_Obj.GetValue(strRelToParent_CurVal)
'* Read the ID of the other table, directly from the relational field
Call fldRelToParent_Obj.GetFieldValue("RELATIONID", strRelToParent_Tbl)
'* Could check that the field is actually a single-relational: fldRelToParent_Obj.GetType = 122
'* Open and lock a new Record, for the other item
Set oParent = Ext.CreateAppRecord( strRelToParent_Tbl )
Call oParent.Read(strRelToParent_CurVal)
If oParent.Lock() Then
'* Read value from the parent item's multi-relational field
Set fldRelToChildren_Obj = oParent.Fields().FindField(strRelToChildren_DBName)
Call fldRelToChildren_Obj.GetValue(strRelToChildren_CurVal)
'* Remove the current child from the list
'* To avoid matching when the ID is a substring of a different ID, wrap value in separators before searching.
SnipVal = ","&Shell.Item.GetID&","
NewValue = Replace(strRelToChildren_CurVal, SnipVal, ",")
'* If the current child was the ONLY value in the field, need to correct the blank value.
'* Correct blank value for multirelational (fld_Obj.GetType = 125) or multiselection (104) is ",,"
If NewValue = "," Then NewValue = ",," End If
Call fldRelToChildren_Obj.SetValue(NewValue)
'* Push change to the DB for the parent item (happens automatically only for Current Item)
Call oParent.Update()
Call oParent.Unlock( true )
End If

0 Likes
forumadmin Absent Member.
Absent Member.

Re: TeamScript - how to enumerate list, build new list, and update item with new list?


Comment posted 9/19/08 by Mark Eliason

Thank you, this was very helpful!

0 Likes
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.