homotechsual / HaloAPI

PowerShell module for the Halo Service Solutions series of software products.
MIT License
49 stars 40 forks source link

[Bug]: Issue with custom fields #13

Closed athornfam2 closed 2 years ago

athornfam2 commented 2 years ago

Contact Details

No response

What happened?

The New-HaloAsset command shows the data in the keyfield but doesn't post to the asset in Halo. The same happens when adding other keyfields (aka custom fields)

Version

1.0.1

Which operating systems have you tested on?

What PowerShell version are you running?

7.1.3

Halo Product

Halo ISTM

Halo Version

v2.88.20

What command did you run?

New-HaloAsset -Asset @{ inventory_number = "$($Device.device_name)"; status_id = "1"; key_field = "$($Device.model)"; client_id = "ID"; client_name = "Company"; site_id = "ID"; assettype_name = "Workstation" }

What was the output of the command?

id                          : 40
inventory_number            : ID
key_field                   : MacBook Air (M1, 2020)
client_id                   : ID
client_name                 : Company
site_id                     : ID
business_owner_id           : 0
business_owner_cab_id       : 0
technical_owner_id          : 0
technical_owner_cab_id      : 0
assettype_id                : 128
assettype_name              : Workstation
inactive                    : False
supplier_id                 : 0
supplier_contract_id        : 0
supplier_sla_id             : 0
supplier_priority_id        : 0
customfields                : {}
itemstock_id                : 0
item_id                     : 0
non_consignable             : False
reserved_salesorder_id      : 0
reserved_salesorder_line_id : 0
sla_id                      : -1
priority_id                 : 0
contract_id                 : -1
goodsin_po_id               : 0
issue_consignment_line_id   : 0
commissioned                : 1
intune_id                   : 
prtg_id                     : 0
device42_id                 : 0
datto_url                   : 
ateraid                     : 
lansweeper_id               : 
lansweeper_url              : 
dlastupdate                 : 8/6/2022 10:19:03 PM
item_cost                   : 0
itglue_id                   : 
auvik_network_id            : 
qualys_id                   : 
use                         : asset
device_number               : 37
status_id                   : 1
third_party_id              : 0
automate_id                 : 0
ninjarmm_id                 : 0
syncroid                    : 0
itglue_url                  : 
datto_alternate_id          : 0
snow_id                     : 0
passportal_id               : 0
auvik_device_id             : 
datto_id                    :
homotechsual commented 2 years ago

Key Fields aren't custom fields - Key Fields are the weird way Halo lets you see selected additional information on the asset summary screen. See here three custom fields set as Key Field 1, 2 and 3. image

The end result of this design by Halo is that you cannot POST to Key Fields - they aren't writeable.

homotechsual commented 2 years ago

To update Custom Fields you need to post with the custom field contents in the customfields property. Which is an array of objects containing the custom field attributes.

image

image

homotechsual commented 2 years ago

Any configured Key Fields will populate themselves when the relevant fields or customfields are populated.

athornfam2 commented 2 years ago

@homotechsual Thanks for that explanation. Being that this module does not have examples in the get-help yet. How would I pass this array?

homotechsual commented 2 years ago

Got an example of the field you're trying to set @athornfam2 ?

athornfam2 commented 2 years ago

New-HaloAsset -Asset @{ inventory_number = "$($Device.device_name)"; status_id = "1"; client_id = "12"; client_name = "Company LLC"; site_id = "18"; assettype_name = "Workstation"; {customfields @{serial_number = "$($Device.serial_number)"; os_version = "$($Device.os_version)"; model = "$($Device.model)"} } }

The fields I'm trying to parse from our RMM/MDM solution are below

Model Serial OS Version End User Agent Removed Disc Size Processor Ram Memory

They are being parsed from a json export which does work excluding the passing of custom fields.

homotechsual commented 2 years ago

So first things first is this requires a little prep to get the field IDs - Get-HaloField will give you the field IDs - these should be fairly static.

Here's the simple example setting the processor (which has the field ID 122 for our test instance):

New-HaloAsset -Asset @{ inventory_number = "PSModuleTest01"; status_id = "1"; client_id = "2"; client_name = "Terry's Chocolates"; site_id = "2"; assettype_name = "Workstation"; fields = @(@{ id = 122; value = "AMD Ryzen Test"})}
homotechsual commented 2 years ago

You'll have to identify which of the fields you want to set are core field and which are custom fields.

athornfam2 commented 2 years ago

Thank you so much @homotechsual and the work you do.

homotechsual commented 2 years ago

Reopen if you get stuck again - still working on better documentation throughout :-)

athornfam2 commented 2 years ago

Maybe I closed it too soon. How would I go about setting multiple custom fields?

homotechsual commented 2 years ago

New-HaloAsset -Asset @{ inventory_number = "PSModuleTest01"; status_id = "1"; client_id = "2"; client_name = "Terry's Chocolates"; site_id = "2"; assettype_name = "Workstation"; fields = @(@{ id = 122; value = "AMD Ryzen Test"}, @{ ... ... })}

homotechsual commented 2 years ago

@{... ...} would be the second custom field object. If you're setting a single field you have re-post the full array of custom fields. So if you're editing an existing object you should pull in the custom fields - change or add the new ones and then re-post the entire thing. Otherwise Halo will just empty the array and only set the single field.

homotechsual commented 2 years ago

For example to set both model and processor.

Set-HaloAsset -Asset @{ id = "11"; inventory_number = "PSModuleTest01"; status_id = "1"; client_id = "2"; client_name = "Terry's Chocolates"; site_id = "2"; assettype_name ="Workstation"; fields = @(@{ id = 122; value = "AMD Ryzen Test"}, @{ id = 51; value = "Test Model"})}

Just doing:

New-HaloAsset -Asset @{ id = "11"; inventory_number = "PSModuleTest01"; status_id = "1"; client_id = "2"; client_name = "Terry's Chocolates"; site_id = "2"; assettype_name ="Workstation"; fields = @(@{ id = 51; value = "Test Model"})}

Gives you: image

Even if Processor etc are already set.