Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get a field from a CSV into Assets due to DateTime error

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2023

Hi there,

I have a script where I am importing Intune data into Assets via a POST from powershell.

I am stuck trying to get the fields that are date and time over as they are a text string when it comes into Powershell and turned into JSON and isn't recognised when it is sent over to Assets.  If the Assets attribute was text it works fine, but I need to build some automations around these fields that are going to do date calcuations.

The value looks like this in the JSON

{
                           "objectTypeAttributeId":  385,
                           "objectAttributeValues":  [
                                                         {
                                                             "value":  "17/01/2023 14:41"
                                                         }

 

but it is text.

I am not sure what to do in order to get Assets to accept this as a datetime value?

When I am building the customobject that sets the fields for the JSON I do this conversion

$user | Add-Member -NotePropertyName 'Warranty Expiry Date' -NotePropertyValue $("{0:dd-MM-yyyy HH:mm}" -f $user."Warranty Expiry Date") -Force

but is Assets looking for the field in a particular format to be passed over and accepted as a Datetime?

1 answer

1 accepted

0 votes
Answer accepted
Mikael Sandberg
Community Champion
January 24, 2023

Assets expect the format of the date to look like this:

YYYY-MM-DDTHH:mm:ssZ

And it should be in UTC time zone.

Mikael Sandberg
Community Champion
January 24, 2023

Here is an example from an import that I have that updates asset objects twice a day:

2022-11-09T22:05:01+00:00

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2023

It seems like the process is falling over itself when it comes to the AM / PM side of things.

 

I have this function;

function Convert-StringToDatetimeJSON {
param (
[string]$inputString
)
$date = [datetime]::ParseExact($inputString, "d/MM/yyyy H:mm", $null)
$json = $date.ToString("yyyy-MM-ddTHH:mm:ss.sssZ")
return $json
}

which takes a date and time like that 17/01/2023 14:15 but then it turns that to AM and if there is this 17/01/2023 1:15 it makes that PM? 

Not sure where it is getting confused getting into Assets.

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2023

Needed to offset the date;

function Convert-StringToDatetimeJSON {
param (
[string]$inputString
)
$date = [datetime]::ParseExact($inputString, "d/MM/yyyy H:mm", $null)
$dateWithOffset = [DateTimeOffset]$date
$json = $dateWithOffset.ToString("yyyy-MM-ddTHH:mm:ss.ssszzz")
return $json
}

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events