Thanks Michael.  Not sure this is worth posting - it is pretty basic, but this 
is what I ended up with.  It is a script that can add a value to an existing 
list item - and if the listitem is undefined it creates a listitem.  There is 
not much/any error checking.  It works OK in my environment.



<job id="ZTIAddToList">
   <runtime>
      <named name="NameOfListItem"
             helpstring="Name of the ListItem you want to add to"
             type="string"
             required="true" />
      <named name="ValueToAdd"
             helpstring="Value to be appended to list"
             type="string"
             required="true" />
   </runtime>
   <script language="VBScript" src="ZTIUtility.vbs"/>
   <script language="VBScript" src="ZTIDataAccess.vbs"/>
   <script language="VBScript">

' //***************************************************************************
' // ***** Script Header *****
' //
' //   Author: Todd Miller
' //
' //
' //
' //   File:      ZTIAddToList.wsf
' //
' //   Version:   1
' //
' //   Purpose:   Take a ItemList and add an element to it.  If the ItemList is 
not defined already, it is created.
' //
' //   Usage:     cscript.exe ZTIAddToList.wsf /NameOfListItem:value 
/ValueToAdd:value
' //
' //
' //   History:
' //   1    TM    16.03.2016   Created initial script
' //
' //
' //   Disclaimer
' //   This script is provided "AS IS" without express
' //   or implied warranty of any kind.
' //
' // ***** End Header *****
' //***************************************************************************

Option Explicit
RunNewInstance

'//----------------------------------------------------------------------------
'//
'// Global constant and variable declarations
'//
'//----------------------------------------------------------------------------



'//----------------------------------------------------------------------------
'// End declarations
'//----------------------------------------------------------------------------

'//----------------------------------------------------------------------------
'//  Main Class
'//----------------------------------------------------------------------------

Class ZTIAddToList

                
'//----------------------------------------------------------------------------
                '//  Class instance variable declarations
                
'//----------------------------------------------------------------------------

                Dim iRetVal

                
'//----------------------------------------------------------------------------
                '//  Constructor to initialize needed global objects
                
'//----------------------------------------------------------------------------

                Private Sub Class_Initialize

                                iRetVal = Success

                End Sub


                
'//----------------------------------------------------------------------------
                '//  Main routine
                
'//----------------------------------------------------------------------------

                Function Main

                                ' Define local variables
                                Dim sValueToAdd, sListItem, oTemp

                                ' Check if NameOfListItem has been provided
                                If oEnvironment.Item("NameOfListItem") = "" Then
                                                oLogging.CreateEntry "No 
ListItem Name supplied.", LogTypeError
                                                iRetVal = Failure
                                                Main = iRetVal
                                End If

                                ' Check if ValueToAdd has been provided
                                If oEnvironment.Item("ValueToAdd") = "" Then
                                                oLogging.CreateEntry "No 
ValueToAdd supplied.", LogTypeError
                                                iRetVal = Failure
                                                Main = iRetVal
                                End If

                                sValueToAdd = oEnvironment.Item("ValueToAdd")
                                sListItem = oEnvironment.Item("NameOfListItem")
                                oLogging.CreateEntry "Adding " & sValueToAdd & 
" to " & sListItem & " creating it.",LogTypeInfo
                                If oEnvironment.Exists(sListItem) then
                                                oLogging.CreateEntry sListItem 
& " exists, appending to it.",LogTypeInfo
                                                Set oTemp = 
oEnvironment.ListItem(sListItem)
                                else
                                                oLogging.CreateEntry sListItem 
& " does not exist, creating it.",LogTypeInfo
                                                Set oTemp = 
CreateObject("Scripting.Dictionary")
                                                oLogging.CreateEntry "oTemp is 
created.",LogTypeInfo
                                End If
                                If not oTemp.Exists(sValueToAdd) then
                                                oLogging.CreateEntry "Adding" & 
sValueToAdd & " to temp array",LogTypeInfo
                                                oTemp.Add sValueToAdd,""
                                                oLogging.CreateEntry "Added " & 
sValueToAdd & " to temp array" ,LogTypeInfo
                                                
oEnvironment.ListItem(sListItem) = oTemp
                                                oLogging.CreateEntry "Replaced 
" & sListItem & " with temp array" ,LogTypeInfo
                                Else
                                                oLogging.CreateEntry 
sValueToAdd & " was already in " & sListItem ,LogTypeInfo
                                End If



                                ' Clear supplied Parameters to avoid side 
effects on future calls
                                oLogging.CreateEntry "Clear supplied 
parameters.", LogTypeInfo
                                oEnvironment.Item("ValueToAdd") = ""
                                oEnvironment.Item("NameOfListItem") = ""

                                Main = iRetVal

                End Function

End Class

   </script>
</job>


From: [email protected] [mailto:[email protected]] On 
Behalf Of Michael Niehaus
Sent: Wednesday, March 16, 2016 5:05 PM
To: [email protected]
Subject: [MDT-OSD] RE: Append an item to MDT ListItem?

Slight tweaks:

Set oTemp = oEnvironment.ListItem("TheList")
If not oTemp.Exists("NewItem") then
    oTemp.Add "NewItem",""
    oEnvironment.ListItem("TheList") = oTemp
End if

-MTN

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Miller, Todd
Sent: Wednesday, March 16, 2016 3:01 PM
To: [email protected]<mailto:[email protected]>
Subject: [MDT-OSD] Append an item to MDT ListItem?

I should know this and I am drawing a blank.
In an MDT script, what is the process to add a value to an existing Itemlist?



Does the code below look correct?  Not sure about this line --- oTemp.Add = 
"New",""
What is that trailing "" for?


oTemp = oEnvironment.ListItem("TheList")
If not oTemp.Exists("NewItem") then
    oTemp.Add = "NewItem",""
    oEnvironment.ListItem("TheList") = oTemp
End if





________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the 
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and 
may be legally privileged.  If you are not the intended recipient, you are 
hereby notified that any retention, dissemination, distribution, or copying of 
this communication is strictly prohibited.  Please reply to the sender that you 
have received the message in error, then delete it.  Thank you.
________________________________


________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the 
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and 
may be legally privileged.  If you are not the intended recipient, you are 
hereby notified that any retention, dissemination, distribution, or copying of 
this communication is strictly prohibited.  Please reply to the sender that you 
have received the message in error, then delete it.  Thank you.
________________________________

Reply via email to