We have a number of custom scripts that were written in VBScript for SDL Tridion 5.2. These scripts use the TOM API to perform a number of bulk actions on Tridion objects.
Following a recent upgrade to 2011 SP1, we now have a requirement to change the component template used in a large number of component presentations, and the best way to do this would be to run a script to update the necessary pages and component presentations.
Previously, we could run some VBScript similar to the code below to make this change. In 2011 can we still run these scripts to make this sort of change?
Is it as straightforward as enabling Classic ASP on the Content Manager server (Windows 2008 R2)?
<%
'##### CREATE TRIDION API OBJECTS #####
Set TDSE = Server.CreateObject("TDS.TDSE")
Call TDSE.Initialize()
'##### CALL FUNCTION - PASS IN STRUCTURE GROUP STARTING POINT #####
Call UpdateComponentTemplates(TDSE.GetObject("tcm:44-39929-4", OpenModeEditWithFallback, "tcm:0-44-1"))
Sub UpdateComponentTemplates(arg_strStructureGroup)
'##### GET ALL ITEMS WITHIN SPECIFIED STRUCTURE GROUP #####
For Each objItem In arg_strStructureGroup.GetItems
'##### IF ITEM IS A STRUCTURE GROUP #####
If TypeName(objItem) = "StructureGroup" Then
'##### CALL THE FUNCTION AGAIN, PASSING IN THE STRUCTURE GROUP #####
Call UpdateComponentTemplates(objItem)
End If
'##### IF ITEM IS A PAGE #####
If TypeName(objItem) = "Page" Then
For Each objComponent In objItem.ComponentPresentations
'##### CHECK EXISTING COMPONENT TEMPLATE & UPDATE WITH THE NEW ONE #####
If objComponent.ComponentTemplate.ID = "tcm:44-493-32" Then
'objComponent.ComponentTemplate = "tcm:44-216181-32"
'objItem.Save(True)
'##### OUTPUT STATUS MESSAGE #####
Response.Write(objItem.Title & " ......................... UPDATED<br />") & vbCrlf
Response.Flush()
End If
Next
End If
Next
End Sub
Response.Write("<p>Job Done!!!</p>") & vbCrlf
'##### CLEAN UP OBJECTS #####
Set TDSE = Nothing
%>
I know this could probably be done using the Core Service, but without knowledge of this code or .Net, is it still possible to use VBScript to do this?
Yes, this works in 2011 because the TOM COM+ API is still supported. I recently ran a very similar script on a 2011 system successfully. If you’re updating a lot of items you might want to move it to a .net console app because the template or web page might timeout. If you do this then make sure to use marshal.releaseobject for all the TOM objects.