Home Advanced Request Offering

Advanced Request Offering Control Question Mapping

Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

Hi guys,

I have built a large ARO that changes the support team depending on the input of the first question using PowerShell but having to map everything to the description field shows all the other questions that are not used and they would be irrelevant to the other teams.

Does anyone know of a way to use PowerShell or another way to only show the questions/mapped fields which have data and remove the others from showing in the description. Having 20 questions per team means one team may have to scroll past 40 empty questions in the description before getting to theirs.


TIA,

Alfie.

Answers

  • Dijon_BleaseDijon_Blease Customer IT Monkey ✭

    You could have the PowerShell script activity convert the request offering's "UserInput" property to xml and update the description that way. You should be able to filter out the questions that weren't answered.

    $SR_Class = Get-SCSMClass -Name 'System.WorkItem.ServiceRequest$'
    $SR_Obj = Get-SCSMObject -Class $SR_Class -Filter "name -eq 'SR1234'"
    $SR_UserInputs = [xml]$SR_Obj.UserInput
    
    # This would give you the questions and their answers.
    $SR_UserInputs.UserInputs.UserInput
    

    Hopefully, the above code snippet can get you started.

  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Dijon,

    Thank you for this. I am terrible with PowerShell and trying to learn. This is for incidents so I am sure I can update the above snippet.


    Need to understand how to filter the ones that were not answered and then how to return this being successful for it to move on to the next step.


    Kind regards,

  • Dijon_BleaseDijon_Blease Customer IT Monkey ✭

    Yes, you can update it for incidents as well. I could be wrong, but I think the userinput property only shows the prompts that were answered. So, you might not need to filter anything out. If you did, you would just use where-object to find what you are looking for.

    $SR_UserInputs.UserInputs.UserInput | Where-Object {$null -ne $_.Answer}
    
  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭

    Hey @Alfie_Thomas. If you're looking at learning PowerShell and no less with an SCSM focus, I wrote a blog series that'll bring you up to speed quickly.


  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Dijon,


    Thank you again. So I have this working in Powershell and it filters perfectly with the below. How would I make this commit the results If I put this in an activity step.


    I have a Monitor object that checks all incidents raised with a certain classification, then it would hopefully run this PowerShell below to only return the Q's answered to themnnn Ideally update the description of the incident. The last step is to move onto the final PowerShell which would read the description and change the support group depending on the answers in there (have that part working).


    Import-Module SMlets

    $smDefaultComputer = "ssm04"


    $IR_Class = Get-SCSMClass -Name 'System.WorkItem.Incident$'

    $IR_Obj = Get-SCSMObject -Class $IR_Class -Filter "ID"

    $IR_UserInputs = [xml]$IR_Obj.UserInput


    # This would give you the questions and their answers.

    $Ir_UserInputs.UserInputs.UserInput



    Thank you for you're help so far, it's been great!

  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Adam,


    Thank you so much. This is needed to say the least. Will have a look :)


    Kind regards,

  • Dijon_BleaseDijon_Blease Customer IT Monkey ✭

    No problem. You will want to first loop through the prompts and save them to a string. Then you can update the IR's description property using the SMLETS "Set-SCSMObject" cmdlet.

    Take a look at part 3 of @Adam_Dzyacky PowerShell blog series. He has some great examples on how to update the properties of work items.

  • Alfie_ThomasAlfie_Thomas Customer IT Monkey ✭

    Hi Dijon,

    Getting somewhere (I think). I will post the script I am using below which doesn't work with the Error:


    #### XML VERSION CAUSING ERROR########

    $irClass = Get-SCSMClass –name "System.WorkItem.Incident$" -computername "d1scssm04"

    Get-SCSMObject –class $irClass –filter "Name -eq 'IR81850'" -computername "d1scssm04"

     $IR_UserInputs = [xml]$IR_Obj.UserInput

     $Ir_UserInputs.UserInputs.UserInput

     $IR_Value = $Ir_UserInputs.UserInputs.UserInput

     Set-SCSMObject -SMObject $irObj -Property "Description" -Value $IR_Value 


    ERROR:

    Set-SCSMObject : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Value'. Specified method is not supported.

    At line:9 char:66

    + ... -SCSMObject -SMObject $irObj -Property "Description" -Value $IR_Value

    +                                 ~~~~~~~~~

      + CategoryInfo     : InvalidArgument: (:) [Set-SCSMObject], ParameterBindingException

      + FullyQualifiedErrorId : CannotConvertArgument,SMLets.SetSMObjectCommand

     


    This one works but in the description it updates it without formatting:

     ##### NONE XML VERSION WORKING BUT NOT FORMATTED ########

    $irClass = Get-SCSMClass –name "System.WorkItem.Incident$" -computername "d1scssm04"

    Get-SCSMObject –class $irClass –filter "Name -eq 'IR81850'" -computername "d1scssm04"

     $IR_UserInputs = $IR_Obj.UserInput

     $Ir_UserInputs.UserInputs.UserInput

     $IR_UserInputs = $IR_Obj.UserInput

     $IR_Value = $Ir_UserInputs.UserInputs.UserInput

     Set-SCSMObject -SMObject $irObj -Property "Description" -Value $IR_Userinputs

     


    Is there a way to pass through the XML version correctly?


    Thanks.

  • Dijon_BleaseDijon_Blease Customer IT Monkey ✭

    Set-SCSMObject : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Value'. Specified method is not supported.

    Your value "$IR_Value = $Ir_UserInputs.UserInputs.UserInput" is not a string object, it is a collection of xmlelement items. That is probably why you are getting the error above. You're trying to update a string property of the IR (the description) with a non-string object.

    You can try to use a foreach statement to loop through the $IR_Value and append the question and answer for each prompt to a string. You would then use that string as the value in the Set-SCSMObject command. You can look into how to build strings using PowerShell.

    Here is a simple example:

    $description = ''
    foreach ($input in $ir_value) {
    
        $description += "$($input.Question): $($input.Answer)`n"  
    }
    

    Sorry, I don't have access to our environment right now to test more. But hopefully this helps a little.

Sign In or Register to comment.