Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Creating/Importing/Executing NS Tasks via Workflow

Created: 29 Dec 2008 • Updated: 29 Dec 2008 | 10 comments
Language Translations
reecardo's picture
+3 3 Votes
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 10 CommentsJump to latest comment

stuper2's picture

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

0
Login to vote
noodleNT's picture

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?

0
Login to vote
QuietLeni's picture

reecardo,

Is this still valid for Ns 7.1 Jobs and Tasks with WF 7.1?

Kindest regards,

QuietLeni

What is the point of an Asset Management Solution that needs excessive management? Let me help you.

0
Login to vote
reecardo's picture

This is absolutely still valid with 7.*... just remember to use the SMP components geared towards SMP 7 (their namespace will begin with Altiris7.*)

I'm using this method now to interact with Virtual Machine Management tasks in the SMP. Hopefully I'll have some content available for the store soon.

+1
Login to vote
Fernando Ruiz Caro's picture

reecardo,

When you say "I created an empty computer collection on the NS and added the NS machine itself to it. "

Are you refering to create a Filter, isnt it?

Thanks

0
Login to vote
reecardo's picture

Yes, filter/collection is what I meant... I forgot the nomenclature changed between 6 and 7

0
Login to vote
Fernando Ruiz Caro's picture

Thanks reecardo for your rapid response :-)

From the console I have created a Filter and put its GUID in the parameter, but unfortunately crash an error in the last component "Execute Task" :

collectionGUID = "e4ecd47b-e961-46b1-9aa1-a34673a9a2c8"
ErrorMessage = "The request failed with HTTP status 401: Unauthorized."
 
The URL: https://fsocnshes90/altiris/asdk.task/taskmanagementservice.asmx
 
Its looks like a security problem, but i've checked my SMP Credentials and is ok (administrator)
 
 
 
0
Login to vote
reecardo's picture

Attached is a package that shows how to do this in 7.0. I've basically swapped out the NS6 comps for SMP 7 comps. This package should also make an appearance in a video soon. Just rename the .zip to .package.

Another good thing I omitted from this flow (and vid)... it would be a good idea to REMOVE the instance of the task so you don't clutter your SMP. This can be done with a Delete Item Component (a generated ASDK component that comes loaded by default)

AttachmentSize
WorkflowProject3.zip 1.6 MB
0
Login to vote
jobby's picture

Quick question... can a task be called from the NS that is already in the console, or do you have to have the workflow recreate it to have it run?

0
Login to vote
reecardo's picture

If you know the GUID of the task in the SMP, you can run it... you don't have to have the workflow create it for you.

You can get the GUID of the task my just checking its properties I believe.

0
Login to vote