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

Updating dmn_demand_task is not working #264

Open walispeed opened 5 months ago

walispeed commented 5 months ago

Environment

Operating System: windows server 2019
ServiceNow module version: 4.0.3
PowerShell version: 5.1.17763.5576

Hi, thanks for the module. it is really helpful. However, it seems there is something wrong for some table more especially dmn_demand_task.

Steps to reproduce

when using update-servicenowRecord specifically for dmn_demand_task the table used by GET is correct but not by PATCH, we can see that from the original table dmn_demand_task, the table is "converted" to demand task

Expected behavior

dmn_demand_task updated properly

Actual behavior

input table dmn_demand_task "converted" into demand task

Screenshots

Update-ServiceNowRecord -values @{"work_notes"= "test"} -PassThru -Table dmn_demand_task -id DMNTSK0000374 -Verbose VERBOSE: New-ServiceNowQuery - Advanced VERBOSE: { "ContentType": "application/json", "UseBasicParsing": true, "Method": "Get", "Uri": "https://xxx.service-now.com/api/now/table/dmn_demand_task", "Credential": { "UserName": "..." }, "Body": { "sysparm_display_value": "true", "sysparm_limit": 10, "sysparm_fields": "sys_class_name,sys_id,number", "sysparm_query": "number=DMNTSK0000374" } } VERBOSE: GET https://xxx.service-now.com/api/now/table/dmn_demand_task?sysparm_display_value=true&sysparm_limit=10&sysparm_fields=sys_class_name%2Csys_id%2Cnumber&sysparm_query=number%3DDMNTSK0000374 with 0-byte payload VERBOSE: received -1-byte response of content type application/json;charset=UTF-8 DEBUG: {"result":[{"sys_id":"04e613ab871b6150b216c8040cbb35d4","number":"DMNTSK0000374","sys_class_name":"Demand Task"}]} VERBOSE: Total number of records for this query: 1 VERBOSE: Performing the operation "Update values" on target "Demand Task 04e613ab871b6150b216c8040cbb35d4". VERBOSE: { "ContentType": "application/json", "UseBasicParsing": true, "Method": "Patch", "Uri": "https://xxx.service-now.com/api/now/table/Demand Task/04e613ab871b6150b216c8040cbb35d4", "Credential": { "UserName": "..." }, "Body": [ 123, ... ] } VERBOSE: PATCH https://xxx.service-now.com/api/now/table/Demand Task/04e613ab871b6150b216c8040cbb35d4 with -1-byte payload Invoke-WebRequest : The remote server returned an error: (400) Bad Request. At C:\Program Files\WindowsPowerShell\Modules\ServiceNow\Private\Invoke-ServiceNowRestMethod.ps1:144 char:21

gdbarron commented 4 months ago

It looks like providing -Table isn't overriding the class name as it should. Let me dig in and find the issue. Thanks for reporting this.

gdbarron commented 4 months ago

@walispeed I've installed PPM Standard to replicate your issue exactly and I'm unable to do so. The update works as expected. Have you made any changes to the module, eg. updating the list of tables in main.json?

walispeed commented 3 months ago

Hi @gdbarron, I don't think I changed anything in the module. We're running washingtondc version and maybe we customized things at serviceNow level, do you think it can create that behavior ? Or a lack of permission maybe ?


Update : the current service account has no rights to write on this table, maybe then the message we receive from the module is missleading (400 - bad request) should be more a 401 - Unauthorized

walispeed commented 3 months ago

hey @gdbarron, I confirm I did not change anything in the module. I have the same behavior with project task pm_project_task

VERBOSE: { "ContentType": "application/json", "UseBasicParsing": true, "Method": "Get", "Uri": "https://xxx.service-now.com/api/now/table/pm_project_task",

VERBOSE: { "ContentType": "application/json", "UseBasicParsing": true, "Method": "Patch", "Uri": "https://xxx.service-now.com/api/now/table/Project Task/272ee88e87d982d0026f87f30cbb3562"

The table used in the uri used by the Get is not the same as the one for the Patch

gdbarron commented 2 months ago

Hi @walispeed. Can you confirm you are using 4.0.3 of the module? Also, can you provide all the steps you are running starting with New-ServiceNowSession? I see multiple differences in your verbose output from mine. I've tested on multiple machines with v5 and v7.