Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit 94a478f

Browse files
authored
Added function to update user name
Added new function to update employee or contingent worker's login user name to an email-id.
1 parent b1496db commit 94a478f

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
function Set-WorkdayWorkderUserName {
2+
<#
3+
.SYNOPSIS
4+
Sets a Worker's account user name in Workday.
5+
6+
.DESCRIPTION
7+
Sets a Worker's user name in Workday.
8+
9+
.PARAMETER WorkerId
10+
The Worker's Id at Workday.
11+
12+
.PARAMETER WorkerUserName
13+
The Worker UserName to login into Workday.
14+
15+
.PARAMETER WorkerType
16+
Currently supports Employee and Contingent.
17+
18+
.PARAMETER Human_ResourcesUri
19+
Human_Resources Endpoint Uri for the request. If not provided, the value
20+
stored with Set-WorkdayEndpoint -Endpoint Human_Resources is used.
21+
22+
.PARAMETER Username
23+
Username used to authenticate with Workday. If empty, the value stored
24+
using Set-WorkdayCredential will be used.
25+
26+
.PARAMETER Password
27+
Password used to authenticate with Workday. If empty, the value stored
28+
using Set-WorkdayCredential will be used.
29+
30+
.EXAMPLE
31+
32+
Set-WorkdayWorkderUserName -WorkerId 123 -WorkerUserName worker@example.com
33+
34+
.NOTES
35+
This changes the users login name for Workday
36+
37+
#>
38+
39+
[CmdletBinding()]
40+
param (
41+
[Parameter(Mandatory = $true,
42+
Position=0)]
43+
[ValidatePattern ('^[a-fA-F0-9\-]{1,32}$')]
44+
[string]$WorkerId,
45+
[Parameter(Mandatory = $true)]
46+
[ValidatePattern('^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$')] # Since the user name is email-id in this implementation
47+
[string]$WorkerUserName,
48+
[ValidateSet('Employee','Contingent')]
49+
[string]$WorkerType = 'Employee',
50+
[string]$Human_ResourcesUri,
51+
[string]$Username,
52+
[string]$Password
53+
)
54+
55+
if ([string]::IsNullOrWhiteSpace($Human_ResourcesUri)) { $Human_ResourcesUri = $WorkdayConfiguration.Endpoints['Human_Resources'] }
56+
57+
$request = [xml]@'
58+
<bsvc:Workday_Account_for_Worker_Update bsvc:version="v33.0" xmlns:bsvc="urn:com.workday/bsvc">
59+
<bsvc:Worker_Reference>
60+
<bsvc:RefNode xmlns:bsvc="urn:com.workday/bsvc" />
61+
</bsvc:Worker_Reference>
62+
<bsvc:Workday_Account_for_Worker_Data>
63+
<bsvc:User_Name></bsvc:User_Name>
64+
</bsvc:Workday_Account_for_Worker_Data>
65+
</bsvc:Workday_Account_for_Worker_Update>
66+
'@
67+
$employeeref = [xml]@'
68+
<bsvc:Employee_Reference xmlns:bsvc="urn:com.workday/bsvc">
69+
<bsvc:Integration_ID_Reference>
70+
<bsvc:ID bsvc:System_ID="WD-EMPLID"></bsvc:ID>
71+
</bsvc:Integration_ID_Reference>
72+
</bsvc:Employee_Reference>
73+
'@
74+
$contingentref = [xml]@'
75+
<bsvc:Contingent_Worker_Reference xmlns:bsvc="urn:com.workday/bsvc">
76+
<bsvc:Integration_ID_Reference>
77+
<bsvc:ID bsvc:System_ID="WD-EMPLID"></bsvc:ID>
78+
</bsvc:Integration_ID_Reference>
79+
</bsvc:Contingent_Worker_Reference>
80+
'@
81+
82+
if ($WorkerType -eq 'Employee') {
83+
$employeeref.Employee_Reference.Integration_ID_Reference.ID.InnerText = $WorkerId
84+
$request.Workday_Account_for_Worker_Update.Worker_Reference.InnerXml = $employeeref.OuterXml
85+
} elseif ($WorkerType -eq 'Contingent') {
86+
$contingentref.Contingent_Worker_Reference.Integration_ID_Reference.ID.InnerText = $WorkerId
87+
$request.Workday_Account_for_Worker_Update.Worker_Reference.InnerXml = $contingentref.OuterXml
88+
}
89+
90+
# Set Workday employee/congingent worker UserName
91+
$request.Workday_Account_for_Worker_Update.Workday_Account_for_Worker_Data.User_Name = $WorkerUserName
92+
93+
Invoke-WorkdayRequest -Request $request -Uri $Human_ResourcesUri -Username:$Username -Password:$Password | Write-Output
94+
95+
}

0 commit comments

Comments
 (0)