forked from treestryder/powershell_module_workdayapi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSet-WorkdayWorkerDocument.ps1
More file actions
101 lines (83 loc) · 3.71 KB
/
Set-WorkdayWorkerDocument.ps1
File metadata and controls
101 lines (83 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function Set-WorkdayWorkerDocument {
<#
.SYNOPSIS
Uploads a document to a Worker's records in Workday.
.DESCRIPTION
Uploads a document to a Worker's records in Workday.
.PARAMETER WorkerId
The Worker's Id at Workday.
.PARAMETER WorkerType
The type of ID that the WorkerId represents. Valid values
are 'WID', 'Contingent_Worker_ID' and 'Employee_ID'.
.PARAMETER Path
The Path to the document file to upload.
.PARAMETER StaffingUri
Staffing Endpoint Uri for the request. If not provided, the value
stored with Set-WorkdayEndpoint -Endpoint Staffing is used.
.PARAMETER Username
Username used to authenticate with Workday. If empty, the value stored
using Set-WorkdayCredential will be used.
.PARAMETER Password
Password used to authenticate with Workday. If empty, the value stored
using Set-WorkdayCredential will be used.
.EXAMPLE
Set-WorkdayWorkerDocument -WorkerId 123 -Path Document.pdf
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true,
Position=0)]
[ValidatePattern ('^[a-fA-F0-9\-]{1,32}$')]
[string]$WorkerId,
[ValidateSet('WID', 'Contingent_Worker_ID', 'Employee_ID')]
[string]$WorkerType = 'Employee_ID',
[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string]$Path,
[string]$FileName,
[Parameter(Mandatory = $true)]
[ValidateSet('WID', 'Document_Category__Workday_Owned__ID', 'Document_Category_ID')]
[string]$CategoryType,
[Parameter(Mandatory = $true)]
[string]$CategoryId,
[string]$Comment,
[string]$StaffingUri,
[string]$Username,
[string]$Password
)
Add-Type -AssemblyName "System.Web"
if ([string]::IsNullOrWhiteSpace($StaffingUri)) { $StaffingUri = $WorkdayConfiguration.Endpoints['Staffing'] }
$request = [xml]@'
<bsvc:Put_Worker_Document_Request bsvc:version="v30.0" bsvc:Add_Only="false" xmlns:bsvc="urn:com.workday/bsvc">
<bsvc:Worker_Document_Data>
<bsvc:Filename>Filename</bsvc:Filename>
<!--Optional:-->
<bsvc:Comment></bsvc:Comment>
<bsvc:File>Z2Vybw==</bsvc:File>
<bsvc:Document_Category_Reference>
<bsvc:ID bsvc:type="CategoryType">CategoryId</bsvc:ID>
</bsvc:Document_Category_Reference>
<bsvc:Worker_Reference>
<bsvc:ID bsvc:type="Employee_ID">Employee_ID</bsvc:ID>
</bsvc:Worker_Reference>
<bsvc:Content_Type>ContentType</bsvc:Content_Type>
</bsvc:Worker_Document_Data>
</bsvc:Put_Worker_Document_Request>
'@
$request.Put_Worker_Document_Request.Worker_Document_Data.Worker_Reference.ID.InnerText = $WorkerId
if ($WorkerType -eq 'Contingent_Worker_ID') {
$request.Put_Worker_Document_Request.Worker_Document_Data.Worker_Reference.ID.type = 'Contingent_Worker_ID'
} elseif ($WorkerType -eq 'WID') {
$request.Put_Worker_Document_Request.Worker_Document_Data.Worker_Reference.ID.type = 'WID'
}
if ([string]::IsNullOrWhiteSpace($FileName)) {
$FileName = [string] (Split-Path -Path $Path -Leaf)
}
$request.Put_Worker_Document_Request.Worker_Document_Data.Filename = $FileName
$request.Put_Worker_Document_Request.Worker_Document_Data.File = [System.Convert]::ToBase64String( [system.io.file]::ReadAllBytes( $Path ) )
$request.Put_Worker_Document_Request.Worker_Document_Data.Document_Category_Reference.ID.type = $CategoryType
$request.Put_Worker_Document_Request.Worker_Document_Data.Document_Category_Reference.ID.InnerText = $CategoryId
$request.Put_Worker_Document_Request.Worker_Document_Data.Comment = $Comment
$request.Put_Worker_Document_Request.Worker_Document_Data.Content_Type = [System.Web.MimeMapping]::GetMimeMapping( $fileName )
Invoke-WorkdayRequest -Request $request -Uri $StaffingUri -Username:$Username -Password:$Password | Write-Output
}