Home Orchestrator

Passing Data from one Runbook to another

VikVik Member IT Monkey ✭

Hi Guys,

I have a User Account Creation Runbook that is triggered via the the portal, when HR submits a request. The requires an approval. We have a Runbook that fetches any Activity that has a reviewer and emails the reviewer (Email Reviewer).

Is there a way to setup a Runbook (Email Reviewer) to fetch the data submitted in Another Runbook (by HR in User Account Creation Runbook)? We'd like to add these data to the email sent to reviewer for them to review it straight from the email, instead of them going to Service Manager Console/Portal to see what HR entered.


Many thanks in advance.

Answers

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    edited July 2022

    @Vik You could write the data into the Description of the Runbook Automation Activity and then get that Activity in your next runbook - Then you just pass the description from the first runbook to the mail, which you send out in the second one.

    You would have to get the activity by Child ID. I can help you if you need a script for that.

  • VikVik Member IT Monkey ✭

    Hi @Simon_Zeinhofer , that would be great, thanks.

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    edited July 2022

    Hello @Vik , this is the code:

    import-module smlets
    $scsm = 'YOUR SCSM SERVER'
    $SRName = 'ID OF YOUR ServiceRequest'
    $cID = 'CHILD ID YOU ARE LOOKING FOR'
    
    
    $srClass = Get-SCSMClass 'System.WorkItem.ServiceRequest$' -ComputerName $scsm
    
    
    $sr = Get-SCSMObject -Class $srClass -Filter "Name -eq '$SRName'" -ComputerName $scsm
    
    
    $relObj = Get-scsmrelatedobject -SMObject $sr -ComputerName $scsm
    $returnObject = [System.Collections.ArrayList]::new()
    
    Function Get-SAsAndPAs
    {
    
    
        Param (
    
    
            $object,
            $ChildID,
            $retObject
        )
    
    
    
    
        $relAct = Get-SCSMRelatedObject -SMObject $object -ComputerName $scsm
    
    
        foreach($a in $relAct)
        {
    
    
            if($a.ClassName -eq 'System.WorkItem.Activity.ParallelActivity' -or $a.ClassName -eq 'System.WorkItem.Activity.SequentialActivity')
            {
    
    
               Get-SAsAndPAs -object $a -ChildID $ChildID -retObject $returnObject
    
    
            }
            else
            {
    
    
               Get-Activities -object $a -ChildID $ChildID -retObject $returnObject
    
    
            }
    
    
        }
    
    
    
    
    }
    
    
    Function Get-Activities
    {
    
    
        Param(
    
    
            $object,
            $ChildID,
            $retObject
    
    
        )
    
    
    
    
        
            if($object.ChildID -eq $ChildID)
            {
    
    
                $retObject.Add($object)
                break
            }
    
    
    
    
    }
    
    
    foreach($r in $relObj)
    {
    
    
        if($r.ClassName -eq 'System.WorkItem.Activity.ParallelActivity' -or $r.ClassName -eq 'System.WorkItem.Activity.SequentialActivity')
        {
    
    
            Get-SAsAndPAs -object $r -ChildID $cID -retObject $returnObject
    
    
        }
        else
        {
    
    
            Get-Activities -object $r -ChildID $cID -retObject $returnObject
    
    
        }
    
    
    
    
    }
    
    
    $workItemID = $returnObject[0].Id
    $workItemGUID = $returnObject[0].__InternalId.Guid
    $workItemDescription = $returnObject[0].Description
    
    
    
    
    
    
    

    SMlets have to be installed on the server you are running the script (your SCO runbook server)

    On top of the code you have to insert values from your environment, the Service Request and the Child ID you are looking for.

    You can just create a new .net activity in your sco runbook, copy the script and use the 3 variables at the bottom inside your published data. The last one is the description, which you want to use in your other runbook.

    If you need a script for getting all the child IDs from a SR template, I have written a little script, which might be helpful:


    import-module smlets
    $scsm = 'YOUR SCSM SERVER'
    
    
    $activityTemplates = [System.Collections.ArrayList]::new()
    $activityTemplates.Add("SRName,ActivityName,ChildID")
    $templateName = "TEMPLATENAME"
    
    
    Function Get-Activities
    {
    
    
        Param(
            
            $Template,
            $ObjectCollection
    
    
        )
    
    
    
    
        $aHashtable = @{}
        $pCollection = $ObjectCollection.PropertyCollection
        foreach($pr in $pCollection)
        {
    
    
            $aHashtable.Add($pr.Path,$pr.MixedValue)
    
    
        }
    
    
        $aString = $Template.DisplayName + "," + $aHashTable.'$Context/Property[Type=''CustomSystem_WorkItem_Library!System.WorkItem'']/Title$' + "," + $aHashTable.'$Context/Property[Type=''CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity'']/ChildId$'
        $activityTemplates.Add($aString)
    
    
    }
    
    
    Function Get-SAsAndPAs{
    
    
        Param(
            
            $Template,
            $ObjectCollection
    
    
        )
    
    
        $objColl = $ObjectCollection.ObjectCollection
        foreach($obj in $objColl)
        {
    
    
            if((-not $obj.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.SequentialActivity'")) -and (-not $obj.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.ParallelActivity'")))
            {
    
    
                Get-Activities -Template $Template -ObjectCollection $obj
    
    
            }
            
            elseif(($obj.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.SequentialActivity'")) -or ($obj.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.ParallelActivity'")))
            {
    
    
                Get-SAsAndPAs -Template $Template -ObjectCollection $obj
    
    
            }
    
    
        }
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    $temp = Get-scsmobjecttemplate -ComputerName $scsm | ? { $_.DisplayName -like "$templateName*" }
    
    
    
    
        foreach($o in $temp.ObjectCollection)
        {
    
    
        if((-not $o.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.SequentialActivity'")) -and (-not $o.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.ParallelActivity'")))
        {
            
                Get-Activities -Template $temp -ObjectCollection $o
    
    
        }
        elseif(($o.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.SequentialActivity'")) -or ($o.Path.Contains("TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity.ParallelActivity'")))
        {
                
                
                Get-SAsAndPAs -Template $temp -ObjectCollection $o
            
        }
            
        }
    

    The code above gives you all the child IDs from your template (The name of the template has to be written on top in the variable $templateName")

    Smlets is fundamental here as well.

Sign In or Register to comment.