Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Creating/Importing/Executing NS Tasks via Workflow

Updated: 29 Dec 2008 | 2 comments
reecardo's picture
+1 1 Vote
Login to vote

This article demonstrates how to create (or rather, import) tasks into an NS and execute them on the fly.

Prerequisites: This workflow takes advantage of a pre-generated ASDK component as well as a generated web service component (generated against the ASDK Task Management Service on your NS).

I'm going to create a workflow that will create a text file on the hard drive (C:\) of the NS. The entire workflow is below:

We'll cover each of the components in the flow:

  • Create NS Credentials component: with this comp, specify the NS on which you plan to create the task (any method is acceptable)
  • Create Globally Unique Value: this will put a new GUID on the stream, called newGUID in our example. This GUID will represent the GUID of the task we intend to create.
  • Add New Data element: this will put a string that represents the name of our task, called NewName in our example. This string represents the name of the task to create on the NS,
  • Merge Text: this "builds" the XML representation of the task to import into the NS. The best way to observe task XML in your NS is to create simple tasks on your NS, then right-click and View them As XML. Be sure that the XML you specify for your task is well-formed; check it in an XML editor before running. Also, especially with Script Task types, because we're basically building a large string of XML, choose a scripting language that relies on line delimiters (i.e. JavaScript vs. VBScript). Our XML is shown below; the text in blue are variables to merge from previously in the flow, while the text in bold describes the task to execute:
    <item guid="{newGUID}" classGuid="{4f1b9b32-b5c6-4d83-8992-f73582217aac}">
    <!-- Type: Altiris.ScriptTask.ScriptTask -->
    <!-- Assembly: Altiris.ScriptTask, Version=6.0.1404.0, Culture=neutral, PublicKeyToken=99b1e4cc0d03f223 -->
    <name>NewName</name>
    <alias />
     <ownerNSGuid>{7e4084c7-11f8-4de4-a8e2-0546461405ad}</ownerNSGuid> 
    <productGuid>{9f9a80fc-2d71-4b08-a1ad-fb146b4af2c6}</productGuid> 
    <itemAttributes>Normal</itemAttributes>
    <itemLocalizations>
    <culture name="">
    <description>Runs a script on computers</description>
    <name>NewName</name>
    </culture> <culture name="en"> 
    <description>Runs a script on computers</description>
     </culture>
     </itemLocalizations>
     <platform configuredProviderGuid="00000000-0000-0000-0000-000000000000" />
     <remoteExecAdvanced> <priority value="Normal" exclusive="True" />
     <kill enforce="True" maxMinutes="30" />
     </remoteExecAdvanced> 
    <scriptText type="JavaScript">var fso = new ActiveXObject("Scripting.FileSystemObject"); var a = fso.CreateTextFile("c:\\woohoo.txt", true); a.WriteLine("yoohoo."); a.Close();</scriptText>
     <scriptAdvanced collectOutput="False" username="" password="" window="ShowNormal" />
    <parentFolderGuid>455ae0db-ec74-455b-b262-89421c96908d</parentFolderGuid> 
    <security owner="@APPLICATION_ID" inherit="True"> 
    <aces>
     <ace type="reserved" name="@APPLICATION_ID">
     <permissionGrants>
    <permissionGrant guid="{ac296df1-eb40-4592-899f-25d5c07d45f6}" name="Write" />
     <permissionGrant guid="{819dae1e-b1a5-4643-81a1-26ef95feb8a8}" name="Change Permissions" />
     <permissionGrant guid="{983a2d22-7a82-4db0-a707-52c7d6b1441e}" name="Read" />
     <permissionGrant guid="{eca6254f-5017-4730-9b3f-5add230829b7}" name="Delete" /> 
    <permissionGrant guid="{726b1c09-7108-450d-ae24-5f8e93135ed6}" name="Clone" />
     <permissionGrant guid="{4ddc04c3-f0a5-4e88-84aa-c44c8c5ebcc4}" name="Read Permissions" />
     <permissionGrant guid="{fbce1052-3bcf-4734-9701-d5bdb08fe64c}" name="Run" /> 
    </permissionGrants> 
    </ace>
     </aces>
     </security> 
    <itemReferences>
     <itemReference guid="{c6c14a32-2dd0-458c-9300-ab24e8d016fd}" hint="tasktypeitemfortask" type="DependentChild">
     <item guid="{c6c14a32-2dd0-458c-9300-ab24e8d016fd}" classGuid="{c7bf6fbb-8067-4a1b-9dea-f37fd7d0cfd4}">
     <!-- Type: Altiris.ScriptTask.ScriptTaskType -->
     <!-- Assembly: Altiris.ScriptTask, Version=6.0.1404.0, Culture=neutral, PublicKeyToken=99b1e4cc0d03f223 -->
     <name>Script</name> 
    <alias /> 
    <ownerNSGuid>{7e4084c7-11f8-4de4-a8e2-0546461405ad}</ownerNSGuid> 
    <productGuid>{c5c92942-41a8-4221-80a5-d41b3d585701}</productGuid> 
    <itemAttributes>Normal</itemAttributes>
     <itemLocalizations>
     <culture name=""> 
    <description>Script Task Definition Item</description> 
    <name>Script</name> 
    </culture>
     </itemLocalizations> <parentFolderGuid>b677de98-acc5-40be-91ea-5a6ef5a3f784</parentFolderGuid>
    <security owner="@APPLICATION_ID" inherit="True">
    <aces>
    <ace type="reserved" name="@APPLICATION_ID">
     <permissionGrants>
     <permissionGrant guid="{ac296df1-eb40-4592-899f-25d5c07d45f6}" name="Write" />
    <permissionGrant guid="{819dae1e-b1a5-4643-81a1-26ef95feb8a8}" name="Change Permissions" />
    <permissionGrant guid="{983a2d22-7a82-4db0-a707-52c7d6b1441e}" name="Read" /> 
    <permissionGrant guid="{eca6254f-5017-4730-9b3f-5add230829b7}" name="Delete" /> 
    <permissionGrant guid="{726b1c09-7108-450d-ae24-5f8e93135ed6}" name="Clone" />
     <permissionGrant guid="{4ddc04c3-f0a5-4e88-84aa-c44c8c5ebcc4}" name="Read Permissions" />
    <permissionGrant guid="{c27cdc0e-67aa-415a-9288-c47b9a8e7cc0}" name="Create" /> 
    </permissionGrants>
     </ace> 
    </aces>
     </security>
     <itemReferences /> 
    </item> 
    </itemReference>
    </itemReferences>
     </item>
     
    
  • ImportItemXmlStringComponent: This is a pre-generated ASDK component. Pass in the output from the previous Merge Text component as input.
  • After this component executes, we should see the task get created on the NS. The next few components will execute our new task.
  • Add New Data Element: This will put a string (to represent a GUID) on the stream which we'll use in the next component, called CollectionToRunTaskAgainst in our example. I created an empty computer collection on the NS and added the NS machine itself to it. Then I grabbed the collection's GUID and used it for this variable's value.
  • Merge Text: this "builds" the XML representation of input parameters to pass to the execute Task method. The Execute Task web service in Task Management needs 3 parameters: a run name (can be anything you want), a task GUID (newGUID previously in our stream), and input parameter XML. This XML mainly defines 2 things: task thresholds, and the machine collection to run the task against (in our example, just the NS machine itself). Our XML is shown below; again, make sure it's well-formed before running.
    <inputParameters>
     <parameter>
    <name>@AssignedResources</name>
    <value>CollectionToRunTaskAgainst</value>
    </parameter>
    <parameter> 
    <name>@CompRequirements</name>
     <value> 
    <minWaitTime>1 minutes</minWaitTime> 
    <maxWaitTime>1 minutes</maxWaitTime>
    <minCompletion>1 %</minCompletion> 
    </value>
     </parameter>
     </inputParameters>
     
    
  • Execute Task Component: this component is a generated web service component (specifically, the Execute Task method if the NS Task Management Service). Give it a run name, the newGUID introduced previously on the stream, and the input XML built in the Merge Text component immediately before this one.

After running this flow, the task should create a little text file at the C:\ level. While this is a fairly minor example, hopefully it demonstrates the ability of building, creating and executing custom tasks on the NS via Workflow.

article Filed Under:

Comments

stuper2's picture
07
Jul
2010
0 Votes 0
Login to vote

Great post!

Thanks a lot for this Richard.  It helped when I was learning how to use the Task Management Service.  

noodleNT's picture
07
Dec
2011
0 Votes 0
Login to vote

Min and Max WaitTime

What does this do? It looks like it's causing my task to time out because I am running an imaging job. Should both min and max be set to a larger number or do I only need to change MAX to something like 180 instead of 10?