forked from treestryder/powershell_module_workdayapi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSet-WorkdayWorkerEmail.ps1
More file actions
133 lines (109 loc) · 5.42 KB
/
Set-WorkdayWorkerEmail.ps1
File metadata and controls
133 lines (109 loc) · 5.42 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function Set-WorkdayWorkerEmail {
<#
.SYNOPSIS
Sets a Worker's email in Workday.
.DESCRIPTION
Sets a Worker's email 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 Email
Email address.
.PARAMETER UsageType
Currently supports HOME and WORK.
.PARAMETER Secondary
By default, this will set one non-Primary email address of the same UsageType. To set more than one, use the -Append switch. At some point this command may need to allow specifying a specific email WID to update.
.PARAMETER Append
When used with the Secondary switch, this will add the specified Email as a non-Primary email of the same UsageType.
.PARAMETER Private
Marks the email as not Public in Workday.
.PARAMETER Human_ResourcesUri
Human_Resources Endpoint Uri for the request. If not provided, the value
stored with Set-WorkdayEndpoint -Endpoint Human_Resources 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-WorkdayWorkerEmail -WorkerId 123 -WorkEmail worker@example.com
.NOTES
When setting a primary email, by default, Workday deletes ALL non-primary addresses of the same type.
When using Do_Not_Replace_All="true", Workday will append non-primary addresses, rather than update a current address.
For this behavior, use the -Append switch, with the -Secondary switch.
Otherwise use the -Secondary switch.
#>
[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)]
[ValidatePattern('^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$')]
[Alias('EmailAddress')]
[string]$Email,
[ValidateSet('HOME','WORK')]
[string]$UsageType = 'WORK',
[switch]$Private,
[switch]$Secondary,
[switch]$Append,
[string]$Human_ResourcesUri,
[string]$Username,
[string]$Password
)
if ([string]::IsNullOrWhiteSpace($Human_ResourcesUri)) { $Human_ResourcesUri = $WorkdayConfiguration.Endpoints['Human_Resources'] }
$request = [xml]@'
<bsvc:Maintain_Contact_Information_for_Person_Event_Request bsvc:version="v30.0" bsvc:Add_Only="false" xmlns:bsvc="urn:com.workday/bsvc">
<bsvc:Business_Process_Parameters>
<bsvc:Auto_Complete>true</bsvc:Auto_Complete>
<bsvc:Run_Now>true</bsvc:Run_Now>
<bsvc:Comment_Data>
<bsvc:Comment>Email set by Set-WorkdayWorkerEmail</bsvc:Comment>
</bsvc:Comment_Data>
</bsvc:Business_Process_Parameters>
<bsvc:Maintain_Contact_Information_Data>
<bsvc:Worker_Reference>
<bsvc:ID bsvc:type="Employee_ID">Employee_ID</bsvc:ID>
</bsvc:Worker_Reference>
<bsvc:Effective_Date>Effective_Date</bsvc:Effective_Date>
<bsvc:Worker_Contact_Information_Data>
<bsvc:Email_Address_Data bsvc:Do_Not_Replace_All="true">
<bsvc:Email_Address>Email_Address</bsvc:Email_Address>
<bsvc:Usage_Data bsvc:Public="true">
<bsvc:Type_Data bsvc:Primary="true">
<bsvc:Type_Reference>
<bsvc:ID bsvc:type="Communication_Usage_Type_ID">WORK</bsvc:ID>
</bsvc:Type_Reference>
</bsvc:Type_Data>
</bsvc:Usage_Data>
</bsvc:Email_Address_Data>
</bsvc:Worker_Contact_Information_Data>
</bsvc:Maintain_Contact_Information_Data>
</bsvc:Maintain_Contact_Information_for_Person_Event_Request>
'@
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Reference.ID.InnerText = $WorkerId
if ($WorkerType -eq 'Contingent_Worker_ID') {
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Reference.ID.type = 'Contingent_Worker_ID'
} elseif ($WorkerType -eq 'WID') {
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Reference.ID.type = 'WID'
}
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data.Email_Address = $Email
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Effective_Date = (Get-Date).ToString( 'yyyy-MM-dd' )
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data.Usage_Data.Type_Data.Type_Reference.ID.'#text' = $UsageType
if ($Secondary) {
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data.Usage_Data.Type_Data.Primary = 'false'
if (-not $Append) {
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data.Do_Not_Replace_All = 'false'
}
}
if ($Private) {
$request.Maintain_Contact_Information_for_Person_Event_Request.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data.Usage_Data.Public = 'false'
}
Invoke-WorkdayRequest -Request $request -Uri $Human_ResourcesUri -Username:$Username -Password:$Password | Write-Output
}