@@ -95,6 +95,13 @@ Function Add-ServiceNowAttachment {
95
95
continue
96
96
}
97
97
98
+ If (-not $Table ) {
99
+ $tableName = $tableRecord.sys_class_name
100
+ }
101
+ else {
102
+ $tableName = $Table
103
+ }
104
+
98
105
$auth = Get-ServiceNowAuth - C $Connection - S $ServiceNowSession
99
106
100
107
ForEach ($Object in $File ) {
@@ -111,15 +118,15 @@ Function Add-ServiceNowAttachment {
111
118
# POST: https://instance.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=d71f7935c0a8016700802b64c67c11c6&file_name=Issue_screenshot
112
119
# $Uri = "{0}/file?table_name={1}&table_sys_id={2}&file_name={3}" -f $ApiUrl, $Table, $TableSysID, $FileData.Name
113
120
$invokeRestMethodSplat = $auth
114
- $invokeRestMethodSplat.Uri += ' /attachment/file?table_name={0}&table_sys_id={1}&file_name={2}' -f $tableRecord .sys_class_name , $tableRecord.sys_id , $FileData.Name
121
+ $invokeRestMethodSplat.Uri += ' /attachment/file?table_name={0}&table_sys_id={1}&file_name={2}' -f $tableName , $tableRecord.sys_id , $FileData.Name
115
122
$invokeRestMethodSplat.Headers += @ {' Content-Type' = $ContentType }
116
123
$invokeRestMethodSplat.UseBasicParsing = $true
117
124
$invokeRestMethodSplat += @ {
118
125
Method = ' POST'
119
126
InFile = $FileData.FullName
120
127
}
121
128
122
- If ($PSCmdlet.ShouldProcess ((' {0} {1}' -f $tableRecord .sys_class_name , $tableRecord.number ), (' Add attachment {0}' -f $FileData.FullName ))) {
129
+ If ($PSCmdlet.ShouldProcess ((' {0} {1}' -f $tableName , $tableRecord.number ), (' Add attachment {0}' -f $FileData.FullName ))) {
123
130
Write-Verbose ($invokeRestMethodSplat | ConvertTo-Json )
124
131
$response = Invoke-WebRequest @invokeRestMethodSplat
125
132
0 commit comments