Snow-Shell/servicenow-powershell

Add Support For Change Management APIs

SolidOceanTrust opened this issue · 13 comments

Hello 👋 !
First, I'd like to say Thank You for such an awesome module!!

I have a few use-cases where I need to interact with the ServiceNow "Change Management" /sn_chg_rest endpoints.
I have a working branch which implements this (in limited capacity) but I wanted to see if there was a specific way that you would like to see this implemented.

If not, I'm happy to open a PR and continue the conversation there.

My use cases:

  • Ability to create a new Change Management Record from an existing Change Template (by SySID)
  • Ability to update Change Management Records and CTasks

Thank you very much.

Hey @SolidOceanTrust! I like the idea of working through via a PR. I look forward to seeing what you have done! Thanks.

I'd second this request! Being able to create changes off of the standard change templates within the module would be amazing!

@chrisjeter, is there any reason the sn_chg_rest endpoints must be used as opposed to posting to the change_request table?

I've always used this with no issues:

New-ServiceNowRecord -table change_request -Values @{'short_description'='new change';'chg_model'='routine'} -PassThru

number     short_description         state    assigned_to     approval   cmdb_ci              opened_at
------     -----------------         -----    -----------     --------   -------              ---------
CHG0030007 new change                1                        requested                       2023-03-04 13:56:53

Replace routine with the name of the change model you'd like to use. You can certainly add any another values you want. Not sure if there are any drawbacks to this approach vs the specific APIs.

From my understanding, model name is the name of the change model, which I assumed you meant by template.

image

If you have rights, you can see which ones are setup for your instance by going to 'Change Models'. I replaced the model name with the sysid and that worked as well.

I think the change models are different from the change templates though, are't they? I'm reffering to these:
change_template

@chrisjeter thanks for pointing this out, it's new to me! According to ChatGPT these 2 are in fact different with the template being the simpler of the 2 and a model supporting workflows, etc.

The 2 fields in the change_request table which control a standard change are type and std_change_producer_version. I was able to create a change from a standard change template with New-ServiceNowRecord -table change_request -Values @{'type'='Standard';'std_change_producer_version'='a08e02ec47410200e90d87e8dee4905a'}.

To get the sys_id value for std_change_producer_version you can either manually create a change and get the value from

Get-ServiceNowRecord -table change_request -ID CHGxxxxxxx -Property std_change_producer_version

or

Get-ServiceNowRecord -table std_change_producer_version -Property name,sys_id
sys_id                           name
------                           ----
16c2273c47010200e90d87e8dee49006 Clear BGP sessions on a Cisco router - 1
923504cc47410200e90d87e8dee490e2 Reboot Windows Server - 1
a08e02ec47410200e90d87e8dee4905a Add network switch to datacenter cabinet - 1
deb8544047810200e90d87e8dee490af Decommission local office Domain Controller - 1
f1c8d15147810200e90d87e8dee490f9 Change VLAN on a Cisco switchport - 1

@gdbarron,
I played around with this today. This does indeed work! I had messed with it before trying to get it working and had failed. The missing piece was that type=standard still needed to be set along with std_change_producer_version. Thank you so much for the help and the great module!