Skip to content

Commit c3f1ab1

Browse files
authored
Add-ServiceNowAttachment: Use table name from param (if present) for attachment POST (#161)
* Use table name from param (if present) for attachment POST * Make requested changes for PR 161
1 parent 9a84e9a commit c3f1ab1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ServiceNow/Public/Add-ServiceNowAttachment.ps1

+9-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ Function Add-ServiceNowAttachment {
9595
continue
9696
}
9797

98+
If (-not $Table) {
99+
$tableName = $tableRecord.sys_class_name
100+
}
101+
else {
102+
$tableName = $Table
103+
}
104+
98105
$auth = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession
99106

100107
ForEach ($Object in $File) {
@@ -111,15 +118,15 @@ Function Add-ServiceNowAttachment {
111118
# POST: https://instance.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=d71f7935c0a8016700802b64c67c11c6&file_name=Issue_screenshot
112119
# $Uri = "{0}/file?table_name={1}&table_sys_id={2}&file_name={3}" -f $ApiUrl, $Table, $TableSysID, $FileData.Name
113120
$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
115122
$invokeRestMethodSplat.Headers += @{'Content-Type' = $ContentType }
116123
$invokeRestMethodSplat.UseBasicParsing = $true
117124
$invokeRestMethodSplat += @{
118125
Method = 'POST'
119126
InFile = $FileData.FullName
120127
}
121128

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))) {
123130
Write-Verbose ($invokeRestMethodSplat | ConvertTo-Json)
124131
$response = Invoke-WebRequest @invokeRestMethodSplat
125132

0 commit comments

Comments
 (0)