Snow-Shell / servicenow-powershell

PowerShell module to automate ServiceNow service and asset management. This module can be used standalone, with Azure Automation, or Docker.
Apache License 2.0
359 stars 170 forks source link

Add Support For Change Management APIs #197

Closed SolidOceanTrust closed 1 year ago

SolidOceanTrust commented 2 years ago

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:

Thank you very much.

gdbarron commented 2 years ago

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

chrisjeter commented 1 year ago

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

gdbarron commented 1 year ago

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

chrisjeter commented 1 year ago

Perhaps not? I was hoping to make use of the standard change templates that are available with those endpoints. The only documentation i've been able to find for creating changes based off of those with the api is through those ends points.

On Thu, Mar 2, 2023 at 12:49 PM Greg Brownstein @.***> wrote:

@chrisjeter https://github.com/chrisjeter, is there any reason the sn_chg_rest endpoints must be used as opposed to posting to the change_request table?

— Reply to this email directly, view it on GitHub https://github.com/Snow-Shell/servicenow-powershell/issues/197#issuecomment-1452383251, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIVDSBKGDGQWJXWZFZJNZB3W2DTVFANCNFSM54TDNUNA . You are receiving this because you were mentioned.Message ID: @.***>

SolidOceanTrust commented 1 year ago

💯 agree with @chrisjeter I had to extend the module to support the sn_chg_rest endpoints in order to make a standard change from a template.

I am just a guy trying to automate some ServiceNow stuff. Certainly not an expert.

I have been negligent about getting an PR put together. I will open one soon.

On Fri, Mar 3, 2023, 23:42 chrisjeter @.***> wrote:

Perhaps not? I was hoping to make use of the standard change templates that are available with those endpoints. The only documentation i've been able to find for creating changes based off of those with the api is through those ends points.

On Thu, Mar 2, 2023 at 12:49 PM Greg Brownstein @.***> wrote:

@chrisjeter https://github.com/chrisjeter, is there any reason the sn_chg_rest endpoints must be used as opposed to posting to the change_request table?

— Reply to this email directly, view it on GitHub < https://github.com/Snow-Shell/servicenow-powershell/issues/197#issuecomment-1452383251 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AIVDSBKGDGQWJXWZFZJNZB3W2DTVFANCNFSM54TDNUNA

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/Snow-Shell/servicenow-powershell/issues/197#issuecomment-1454418689, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZATUZ6Z64DZ7IP7NVTTTTW2LB43ANCNFSM54TDNUNA . You are receiving this because you were mentioned.Message ID: @.***>

gdbarron commented 1 year ago

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.

SolidOceanTrust commented 1 year ago

Very interesting!! When you say "model_name" is that the same thing as the sysID of the std change?

Also, fantastic work on this module!! Really saved me some time!!

On Sat, Mar 4, 2023, 08:14 Greg Brownstein @.***> wrote:

I've always used this with no issues:

New-ServiceNowRecord -table change_request -Values @{'short_description'='new change';'chg_model'='put_model_name_here';'description'='woohoo'}.

You can certainly add any another values you want. Not sure if there are any drawbacks to this approach vs the specific APIs.

— Reply to this email directly, view it on GitHub https://github.com/Snow-Shell/servicenow-powershell/issues/197#issuecomment-1454736346, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZATU7NENYDRL7DYYAV5ATW2M543ANCNFSM54TDNUNA . You are receiving this because you were mentioned.Message ID: @.***>

gdbarron commented 1 year ago

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.

SolidOceanTrust commented 1 year ago

🤯🤯🤯🤯🤯🤯

I certainly don't have that level of access to any of my ServiceNow tenants, but I will ask an adult with the right access to test this.

Thank you Greg!!

On Sat, Mar 4, 2023, 10:49 Greg Brownstein @.***> wrote:

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

[image: image] https://user-images.githubusercontent.com/11862024/222914994-02476077-4db4-4d72-afb7-0edb130d64ea.png

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.

— Reply to this email directly, view it on GitHub https://github.com/Snow-Shell/servicenow-powershell/issues/197#issuecomment-1454783320, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZATU4F5EVEZB5ZIKWXN3DW2NQCLANCNFSM54TDNUNA . You are receiving this because you were mentioned.Message ID: @.***>

chrisjeter commented 1 year ago

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

gdbarron commented 1 year ago

@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
chrisjeter commented 1 year ago

@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!

gdbarron commented 1 year ago

238