CA Service Management

Expand all | Collapse all

How do you get all properties on an Incident

  • 1.  How do you get all properties on an Incident

    Posted Sep 08, 2017 02:35 PM

    I have the following snippet from my Powershell script. I've also tried using "property_list" for the listName.

     

    [xml]$sdm_prop_results = $sdm_ws_url.getRelatedListValues($sdm_ws_sid, "cr", "prp",-1, "ref_num = '5148509'",[ref]$return_props,[ref]$count)

     

    This throws the following error

     

    [ERROR] Exception calling "getRelatedListValues" with "7" argument(s): "Internal err
    [ERROR] with api::get_named_list: NOT FOUND"
    [ERROR] At \\wn2013.or.providence.org\users1\p425346\Visual Studio 2013\Projects\ITSM\S
    [ERROR] cripts\DEV\Unresolved_Incident_Reopen\unresolved_incident_reopen.ps1:156 char:3
    [ERROR] + [xml]$sdm_prop_results =
    [ERROR] $sdm_ws_url.getRelatedListValues($sdm_ws_sid, "cr", " ...
    [ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [ERROR] ~~~~~~~~~
    [ERROR] + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    [ERROR] + FullyQualifiedErrorId : SoapException
    [ERROR]


    Suggestions



  • 2.  Re: How do you get all properties on an Incident
    Best Answer

    Broadcom Employee
    Posted Sep 08, 2017 03:09 PM

    Jerry, getRelatedListValues() expects 3 arguments but you passed 7 and that  caused this error. I think you should use

    doSelect() for this purpose. For example

    $sdm_prop_results = $sdm_ws_url.doSelect($sdm_ws_sid, "cr_prp", "owning_cr=\'cr:xxxxx\'",-1)

    where cr:xxxxx is the persid of the incident 5148509, which you can obtain by running something like this

    $sdm_persid_results = $sdm_ws_url.doSelect($sdm_ws_sid, "cr", "ref_num=\'5148509\'", 1)

    and then parse the $sdm_persid_results to receive it.

    Hope this helps a bit. Thanks _Chi



  • 3.  Re: How do you get all properties on an Incident

    Posted Sep 11, 2017 04:38 PM

    I'm currently running the following.  I'm expecting the "value" to be "Break-Fix". However, the output I posted below the code is from that write-host loop. As you can see, I'm getting the names, but not the values. Any suggestions?

     

     

    [xml]$sdm_prop_results = $sdm_ws_url.doSelect($sdm_ws_sid, "cr_prp", "owning_cr='cr:4600986'",-1, $return_objects)

    $propVals = @()

    $attrs = $sdm_prop_results.UDSObjectList.UDSObject.Attributes.Attribute

    foreach ( $attr in $attrs) {

        write-host $attr.AttrName

        Write-Host $attr.AttValue

        Write-Host $attr.DisplayValue

        if ($attr.AttrName -eq "value"){

          $propVals += $attr.AttValue

           }

    }

     

     

    ---------------------------OUTPUT-----------------------------------

    validation_type

      

    id

      

    persistent_id

      

    validation_rule

      

    sequence

      

    value_description

      

    last_mod_dt

      

    owning_cr

      

    required

      

    sample

      

    label

      

    value

      

    description

      

    last_mod_by



  • 4.  Re: How do you get all properties on an Incident

    Broadcom Employee
    Posted Sep 11, 2017 05:00 PM

    I am curious what you have in $return_objects?



  • 5.  Re: How do you get all properties on an Incident

    Posted Sep 11, 2017 05:24 PM

    It's empty. Just for grins and giggles I gave it a unique name and reran it with the same results.

     

    $return_objects_x = @()

    [xml]$sdm_prop_results = $sdm_ws_url.doSelect($sdm_ws_sid, "cr_prp", "owning_cr='cr:4600986'",-1, $return_objects_x)



  • 6.  Re: How do you get all properties on an Incident

    Broadcom Employee
    Posted Sep 12, 2017 10:02 AM

    maybe you can try

    foreach ( $attr in $sdm_prop_results)...



  • 7.  Re: How do you get all properties on an Incident

    Posted Sep 12, 2017 12:00 PM

    So I was looking into how to force PS to enforce explicit variable declaration and ran across "Set-StrictMode -Version 2.0".  I put that in my code and now I get the following error. Not sure why I get the error but that explains why I have no value.

     

    [ERROR] Property 'AttrName' cannot be found on this object. Make sure that it exists.

    [ERROR] At \\wn2013.or.providence.org\users1\p425346\Visual Studio 2013\Projects\ITSM\S

    [ERROR] cripts\DEV\Unresolved_Incident_Reopen\unresolved_incident_reopen.ps1:208 char:4

    [ERROR] + write-host $attr.AttrName

    [ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~

    [ERROR] + CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException

    [ERROR] + FullyQualifiedErrorId : PropertyNotFoundStrict



  • 8.  Re: How do you get all properties on an Incident

    Broadcom Employee
    Posted Sep 12, 2017 12:40 PM

    what happens if you try

    write-host $attr.Attributes.AttrName

    instead of

    write-host $attr.AttrName

    ?

    similar for next 4 statements.

    I am not a PS expert myself but try my best to help(lol)



  • 9.  Re: How do you get all properties on an Incident

    Posted Sep 12, 2017 12:44 PM

    I got it. I misspelled "AttrValue". I'll clean this up and post the whole thing here for future PS noobs.

     

    Thanks so much for your help.



  • 10.  Re: How do you get all properties on an Incident

    Posted Sep 11, 2017 05:27 PM

    On a side note, I'm a c# person dabbling in PS for this effort. If you see something odd in my code you won't hurt my feelings.



  • 11.  Re: How do you get all properties on an Incident

    Posted Sep 11, 2017 04:57 PM

    FYI, my goal here is to read the properties from a closed incident and pass those values as part of a CreateRequest call for a new incident.