Script check ServiceRequest for Assigned User

Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭
Good afternoon, who can help? I need a script that checks if in the ServiceRequest has a assigned user then need to change the status of the this ServiceRequest. I will be grateful to everyone.
Tagged:

Best Answer

Answers

  • Adam_DzyackyAdam_Dzyacky Customer Contributor Monkey ✭✭✭✭✭
    edited July 25
    This should get you started in the right direction

    $mgmtServer = "localhost"
    $srID = "SR1234"

    $srClass = get-scsmclass -name "system.workitem.servicerequest$" -computername $mgmtServer
    $assignedUserRelClass = get-scsmrelationshipclass -name "System.WorkItemAssignedToUser" -ComputerName $mgmtServer
    $sr = get-scsmobject -class $srClass -filter "Name -eq '$srID'" -computername $mgmtServer
    $assignedUser = get-scsmrelationshipobject -bysource $sr -computername $mgmtServer | ?{($_.relationshipid -eq $assignedUserRelClass.id) -and ($_.sourceobject.classname -eq $srClass.name)}

    if (!$assignedUser)
    {
    Set-SCSMObject -SMObject $sr -Property Status -Value "ServiceRequestStatusEnum.Canceled" -computername $mgmtServer
    }
  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭
    This should get you started in the right direction

    $mgmtServer = "localhost"
    $srID = "SR1234"

    $srClass = get-scsmclass -name "system.workitem.servicerequest$" -computername $mgmtServer
    $assignedUserRelClass = get-scsmrelationshipclass -name "System.WorkItemAssignedToUser" -ComputerName $mgmtServer
    $sr = get-scsmobject -class $srClass -filter "Name -eq '$srID'" -computername $mgmtServer
    $assignedUser = get-scsmrelationshipobject -bysource $sr -computername $mgmtServer | ?{($_.relationshipid -eq $assignedUserRelClass.id) -and ($_.sourceobject.classname -eq $srClass.name)}

    if (!$assignedUser)
    {
    Set-SCSMObject -SMObject $sr -Property Status -Value "ServiceRequestStatusEnum.Canceled" -computername $mgmtServer
    }
    Thank you, Adam_Dzyacky, I'll try to figure it out
  • Roman_NepomniashchiiRoman_Nepomniashchii Customer IT Monkey ✭
    This should get you started in the right direction

    $mgmtServer = "localhost"
    $srID = "SR1234"

    $srClass = get-scsmclass -name "system.workitem.servicerequest$" -computername $mgmtServer
    $assignedUserRelClass = get-scsmrelationshipclass -name "System.WorkItemAssignedToUser" -ComputerName $mgmtServer
    $sr = get-scsmobject -class $srClass -filter "Name -eq '$srID'" -computername $mgmtServer
    $assignedUser = get-scsmrelationshipobject -bysource $sr -computername $mgmtServer | ?{($_.relationshipid -eq $assignedUserRelClass.id) -and ($_.sourceobject.classname -eq $srClass.name)}

    if (!$assignedUser)
    {
    Set-SCSMObject -SMObject $sr -Property Status -Value "ServiceRequestStatusEnum.Canceled" -computername $mgmtServer
    }
    I have slightly redesigned this script for my needs and it works. But there is a problem. This script will be used as a workflow, so you need to loop it, it applies to one request $srID = "SR1234", how can you make it apply to requests containing a name such as SR?
Sign In or Register to comment.