Powershell: Create Service Request from Advance Request Offering
Best Answers
-
Shane_White Cireson Support Super IT Monkey ✭✭✭✭✭Hey Robert,
Here is some PowerShell that might help, this is creating the SR and applying the template:
#import the smletsimport-module smlets;#Get the Service Request Class$serviceRequestClass = Get-SCSMClass -name System.WorkItem.ServiceRequest$#Get the enumeration values needed for the lists in the Service Request$serviceRequestArea = get-SCSMEnumeration -Name ServiceRequestAreaEnum.Infrastructure.Backups$serviceRequestPriority = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.High$serviceRequestUrgency = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.High#Specify the title$serviceRequestTitle = “New Infrastructure Server Backup Component”$serviceRequestDescription = "I am a service request for a new infrastructure Backup component, created by PowerShell"#Create a hash table of the Service Request Arguments$serviceRequestHashTable = @{Title = $serviceRequestTitle;Description = $serviceRequestDescription;Urgency = $serviceRequestUrgency;Priority = $serviceRequestPriority;ID = “SR{0}”;Area = $serviceRequestArea}#Create initial Service Request$newServiceRequest = New-SCSMOBject -Class $serviceRequestClass -PropertyHashtable $serviceRequestHashTable -PassThru$serviceRequestId = $newServiceRequest.ID#Get The Service Request Type Projection$serviceRequestTypeProjection = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequestProjection$#Get the Service Request created earlier in a form where we can apply the template$serviceRequestProjection = Get-SCSMObjectProjection -ProjectionName $serviceRequestTypeProjection.Name -filter “ID -eq $serviceRequestId”#Get The Service Request Template$serviceRequestTemplate = Get-SCSMObjectTemplate -DisplayName “SR - Create Service Request Using PowerShell Template”#Apply the template to the Service RequestSet-SCSMObjectTemplate -Projection $serviceRequestProjection -Template $serviceRequestTemplate
Hope this is helpful,
Thanks,
Shane.5 -
Geoff_Ross Cireson Consultant O.G.Something like this:
PS C:\Users\geoff> $Mapping = [xml](Get-SCSMRequestOffering -DisplayName 'My Request').PresentationMappingTemplate PS C:\Users\geoff> $Mapping.Object.Data.PresentationMappingTemplate.Sources.Source | select Id, Prompt Id Prompt -- ------ 00000000-0000-0000-0000-000000000000 26798f0f-2256-4c33-b1b6-11530e5f5df7 Question 1 01669122-6453-47a0-91fe-f57dac78ef5e Question 2 e11e7539-ddc7-4a44-b45d-2dc8715949bd Question 3 0a0d868c-1759-4b7c-9c1b-cabcf7b93ba8 Question 4 6449fbf7-4ada-45b0-b9a8-6ab1036a9a8e Question 5
Geoff5
Answers
Can you please clarify what it is you are trying to achieve so I can understand the purpose of this?
You can use ARO's to create Service Requests and map properties that the user fills in to properties in the SR and you could also have PowerShell running on SR Activites but just want to know what the end goal is for you.
Thanks,
Shane.
You can create a Service Request and apply a Template for sure with PowerShell, are you also trying to map certain information to it or just have it create an SR?
I only ask because I am confused where the relation to Advance Request Offering comes in.
Thanks,
Shane.
Here is some PowerShell that might help, this is creating the SR and applying the template:
#import the smlets
Hope this is helpful,
Thanks,
Shane.
I am thinking that I just need to use that particular class even though it is based on the ServiceRequest Class.
User input is just a very long string field on the SR. Its contains the data in XML.
I suggest you copy the value from an SR created with the ARO manually, and then use it in the powershell, placing your values in as needed.
Geoff
Also, when you refer to parameters... are you referring to the ARO's User Prompts? If so, I have a SQL query against the ServiceManager db that lists the user prompts for a given RO and some of the properties- such as prompt sequence, the prompt's question, the prompt id, the required/display/optional/etc, prompt type (simple list, query prompt, etc...), etc.....
Geoff
From the Class:
From the request offering for the prompt that is mapped to this:
ID Prompt
e34d3400-bff1-49ab-9dcf-737510aaa846 What is your email address?
$Mapping.Object.Data.PresentationMappingTemplate.Sources.Source[x].Targets.Target.Path