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

How do you add associated CIs to a Change record? #243

Closed OldTimerJB closed 1 year ago

OldTimerJB commented 1 year ago

I can create a change record and ctasks for it but cannot figure out how to add hundreds of Server Cis to affected CI list in the change ticket. Does anyone have examples? Also the new change record function doesn't return the new change number. I have to query for it after its created.

OldTimerJB commented 1 year ago

With the help of ChatGPT I was able to figure this out using the below: ChatGPT gave me this code: New-ServiceNowRecord -Table "task_ci" -Fields @{ "task" = $changeSysId "cmdb_ci" = $serverSysId } I was able to change it to this and it worked.. New-ServiceNowRecord -Table "task_ci" -InputData @{ "task" = $changeSysId "ci_item" = $serverSysId }

gdbarron commented 1 year ago

New-ServiceNowChangeRecord has an -InputData parameter you can use directly when creating the change. If you are looking to just pass one item, use the built-in -ConfigurationItem parameter. Also, -PassThru is used to return the details of the new record.

OldTimerJB commented 1 year ago

Thanks the -PassThru switch was the only other thing I needed. Appreciate it.