0 votes

the following script should create a ticket when an onboarding has been submitted in Adaxes:

Import-Module JiraPS       

$password = ConvertTo-SecureString "password"  -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ('adaxes@domain.com', $password)

Set-JiraConfigServer 'https://domain.atlassian.net'
New-JiraSession -Credential $credential

#Format datetime
$dateConversionFormat = "yyyy-MM-dd"
$duedate_origin = $Context.TargetObject.Get("adm-CustomAttributeDate1")
$duedate = $duedate_origin.ToString($dateConversionFormat)

$initiator = Get-AdmUser  -Filter 'mail -like "%initiator%"'

Try{
    $issue = New-JiraIssue -Project "IOO" -IssueType Task -Summary "%param-summary%" -Description "%param-description%" -Labels "Onboarding" -Reporter $initiator.UserPrincipalName
    Set-JiraIssue -Issue $issue.Key -Fields @{ duedate = $duedate } 
    Set-AdmUser "%distinguishedName%" -Add @{"adm-CustomAttributeText20"=$issue.Key} -AdaxesService localhost
    $Context.LogMessage("Opening Jira Ticket $issue.Key with summary: %param-summary%", "Information")
}
Catch{
   $Context.LogException($_.Exception)
}
Finally{
    Remove-JiraSession
}

When running the onboarding process, the following errors appear:

Exception calling "Get" with "1" argument(s): "The 'adm-CustomAttributeDate1' property cannot be found in the cache." Stack trace: at <ScriptBlock>, <No file>: line 16
You cannot call a method on a null-valued expression. Stack trace: at <ScriptBlock>, <No file>: line 17
by (20 points)

1 Answer

0 votes
by (294k points)

Hello,

The error occurs because adm-CustomAttributeDate1 is empty for the user the script is run on. To avoid such issues, use try-catch blocks for retrieving property values. For example, if you use the below approach, the script will exit if the property is empty:

try
{
    $duedate_origin = $Context.TargetObject.Get("adm-CustomAttributeDate1")
}
catch
{
    $Context.LogMessage("Property adm-CustomAttributeDate1 is empty.", "Warning")
    return
}

Related questions

0 votes
0 answers

We've uninstalled the previous version via the "add/Remove Programs" feature in Windows 10, but we still get an error saying that another version of the client is still installed and won't allow us to run the .MSI installer. How can we get around this?

asked Feb 15 by MShep (80 points)
0 votes
0 answers

Hi, how can I change Help Desk to something a little more specific like "Onboarding Portal"? Or a bit more catchy that our HR will like rather then see Help Desk in the left hand corner.

asked Oct 9, 2019 by 6FigureMission (140 points)
0 votes
1 answer

We are looking to use Adaxes to create and manage Managed Service Accounts in the "Managed Service Accounts" OU. Is this possible through Adaxes? Thank you.

asked Nov 14, 2019 by lgibbens (320 points)
0 votes
1 answer

Hello, currently we have an Exchange 2019 Server in Hybrid configuration with Exchange Online. During our user onboarding a mailbox for the user is being created by a ... Remote-Mailboxes in this scenario for newly created AD-Users? Thanks and KR Christian

asked Apr 18 by User0815 (50 points)
0 votes
1 answer

My company has 400+ positions, each with different access levels in our Active Directory (AD). I want to automate the new user onboarding process as much as ... time-consuming than creating over 400 custom commands. Any assistance would be greatly appreciated.

asked Sep 26, 2023 by sysadmin (20 points)
3,589 questions
3,278 answers
8,303 comments
548,122 users