Home Advanced Request Offering

Powershell: Create Service Request from Advance Request Offering

Does anyone know the best approach to creating a service request from a advance request offering using powershell?  Do I just create it from the generic servicerequest class and apply the template or is there another way?

Best Answers

Answers

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭
    Hi Robert,

    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.
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    I have a ADO pipeline that will be creating service requests automatically.  I already have pipelines that create incidents and change requests if there are issues or if a CR needs to be created for a deployment.  I now have a need to create a service request from powershell code using SMLets module.  So I am just trying to automate the creation of this service request so the developer doesn't have to go into the portal to create it.
  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭
    Robert,

    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.
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    I was just trying to see what others potentially are doing.  I am going to try to just use the servicerequest class and apply the template that is given me. 
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    edited April 2019
    Thank you, yes I was able to get it all working this morning by just applying the template.  What I also found out that I needed to apply any custom parameters that I passed after I applied the template in case the template had default values.  Something that I am trying to do right now is to use apply a template that is a custom class based on a service request (it has custom parameters).  So the class is of type ServiceRequest but when I attempt to apply it it gives me the error "Exception Occurred: Exception calling \"ApplyTemplate\" with \"1\" argument(s): \"The template cannot be applied to the instance because the instance is not of the template targets type.\"."

    I am thinking that I just need to use that particular class even though it is based on the ServiceRequest Class.
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    Update, yes that worked.  So my function will just have the ability to pass the class name else it uses the servicerequest class name
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    edited April 2019
    The only issue that I just need to figure out is that when I use the Advance Request Offering it puts all of their inputs under the User Inputs.  I can do the same as well, just won't have mappings from Friendly Names to Parameters.  I wonder if I can get that information from Powershell.  Does anyone know if it is possible to get a Request Offering and see what friendly names are mapped to parameters?  If it is then I can look that up to add to the User Inputs else I will just add the Parameter names.

  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    @Robert_Auten

    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
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    Thank you, yes I just figured that out that it is just a property on the SR in XML format.  Still curious if it is possible to use powershell to check a ARO and see what friendly names are mapped to parameters.  
  • Chris_Chekaluk1Chris_Chekaluk1 Customer Advanced IT Monkey ✭✭✭
    UserInput is a property of System.WorkItem.  In SQL it is an nvarchar(65536) and is stored in the db as an xml string.  I'd suggest looking at a normally created SR to get the xml schema needed for your SR.

    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.....
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    Thank you!  I have it all working good now.  I appreciate everyone's responses here!
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    Geoff, the Id's that exist in the request offering, how can I map that to the mapped property?  I checked the class and the Id for the property does not match to the Id that is in the request offering.  Maybe the Id in the request offering is not the Id for the property in the class that it is mapped to?  
    From the Class:
    SystemType        : System.String
    Length            : 256
    RegExObject       : 
    Type              : string
    AutoIncrement     : False
    Key               : False
    CaseSensitive     : False
    MaxLength         : 256
    MinLength         : 0
    Required          : False
    MinValue          : -2147483648
    MaxValue          : 2147483647
    Scale             : 0
    RegEx             : 
    EnumType          : 
    DefaultValue      : 
    ManagementGroup   : SCSMAdministrators
    ManagementGroupId : 0e1e6fd9-d9e9-b5ff-c295-d5535354c6ca
    Identifier        : 1|jbh_server_services_sr_customparms_mp/a5d0f02dc99e646a|1.0.0.0|CustomParms/CustomEmailAddress||
    Name              : CustomEmailAddress
    Id                : 54e8a8e5-0c0c-b46c-9f85-d7fa4e6685f5
    ParentElement     : CustomParms
    DisplayName       : CustomEmailAddress
    Description       : 
    LanguageCode      : ENU
    InstanceName      : 


    From the request offering for the prompt that is mapped to this:
    ID                                                               Prompt
    e34d3400-bff1-49ab-9dcf-737510aaa846 What is your email address?
  • Robert_AutenRobert_Auten Customer IT Monkey ✭
    Nevermind, the following contains the custom property in the mapping:
    $Mapping.Object.Data.PresentationMappingTemplate.Sources.Source[x].Targets.Target.Path
Sign In or Register to comment.