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
360 stars 170 forks source link

Get-ServiceNowTask #128

Closed Dejulia489 closed 3 years ago

Dejulia489 commented 3 years ago

Added support for Get-ServiceNowTask

gdbarron commented 3 years ago

Hi @Dejulia489 and thanks for your PR. Can you please explain the rationale and examples for wanting a query against the task base table? As of today, we have Get functions for many child tables as well as generic table functions so I'm not sure where this fits in.

Dejulia489 commented 3 years ago

I am not sure I understand the question. You have support to return Requests, Incidents and Change Requests why not tasks?

image

gdbarron commented 3 years ago

Your code gets records from the task table. This table is a base table which others inherit from. When you query from task you may get a change request record, you may get an incident record. Here's what's in my task table from a developer instance:

image

As we have functions for some of the typical tables, I'm not sure why this is necessary. It's possible I'm just missing the point which is why I was hoping you could explain.

Per chance, are you thinking this is the Catalog Task table sc_task?

Dejulia489 commented 3 years ago

Thank you for elaborating! I am not to familiar with table structure for ServiceNow. I am trying to retrieve a Change Task from the api and I was able to do that via the task table. Is there another table I should query instead?

gdbarron commented 3 years ago

When child tables are created from base tables, typically, fields are added. So, querying task won't always get you the full set of fields as is the case with change task. I'd recommend Get-ServiceNowRecord -table 'change_task'. This function was released in v2.2 so be sure to grab that if you don't have it yet. We could look to add another function such as Get-ServiceNowChangeTask, but I feel like that's a losing battle given how many tables there are and would like to get away from that.

Dejulia489 commented 3 years ago

Thanks for the information. I updated the function to use the change_task table and updated the function name to Get-ServiceNowChangeTask.

Since this isn't super clear how to return specific types of requests with all their fields I recommend that you include this function in the module. As well as the other functions for querying specific task types. At least for the out of box tasks created by ServiceNow. If you can simplify the module end user's experience with a few additional functions then I don't really see the downside. - My $0.02 :)

Thanks for all the help and prompt responses!

gdbarron commented 3 years ago

Hi @Dejulia489. I've added an argument completer to allow tab ahead/completion for the -Table property of Get-ServiceNowRecord. This means you can now cycle through the table names the module knows about. The 'common' name is used instead of the actual table name to make it easier for folks that aren't aware of the table names. Eg., Get-ServiceNowRecord -Table 'Change Task'. Hopefully this is clear and helps folks just getting started without the need for a Get- function for every table.