Jump to content

Assistance re. updating assets in PowerShell


Recommended Posts

Hello,

I am trying to update some assets in Hornbill from a spreadsheet. In particular i am trying to insert/update the Serial Numbers where they don't match in Hornbill on the spreadsheet.

The first things I do in the script (which works) is import the contents of the spreadsheet into PowerShell, then loop through each of the rows and check the corresponding record in Hornbill.

If there is no match, then this should run:

Write-host "$h_asset_number"
Write-Host "`tAsset ID:`t$h_asset_id"
Write-Host "`t"
Write-Host "`tSerial Number"
Write-Host "`t`tChange: $h_asset_serial_number ===> $serialNumber"
Write-Host "`t"

Add-Param       "application" "com.hornbill.servicemanager"
Add-Param       "entity" "AssetsComputer"

Open-Element    "searchFilter"
	Add-Param       "assetId" "$h_asset_id"
Close-Element   "searchFilter"

Add-Param       "serialNumber" "$serialNumber"

# Invoke XMLMC call, output returned as PSObject
$xmlmcUpdate = Invoke-XMLMC "apps/com.hornbill.servicemanager/AssetsComputer" "updateAssetComputer"

if($xmlmcUpdate.status -eq "ok") 
{
	Write-Host -ForegroundColor Green "Success! Asset updated in Hornbill"
}
else
{
  	Write-Host -ForegroundColor Red "FAILED!"
  	# API call status not OK - return status and error to console
  	"API Call Status : " + $xmlmcUpdate.status
  	"Error Returned  : " + $xmlmcUpdate.error
}

($h_asset_id is the asset number found in the previous invoke-xmlc which compares the serial number from the spreadsheet to Hornbill and returns if there is no match)

No matter what I do, i cannot seem to get the Hornbill record to be updated. Everything works instead of where i am trying to invoke-XMLC. I get the following error message with this version of the script:

FAILED!
API Call Status : fail
Error Returned  : FlowCode Exception (com.hornbill.servicemanager/entities/AssetsComputer/fc_ops/updateAssetComputer): Input parameter validation error: The element <application> was not ex
pected at location '/methodCall/params/application'

Can someone assist? This may be just a silly little thing i've missed out.

Thanks,

Samuel

Link to comment
Share on other sites

@samwoo

It looks like you constructing incorrect XML for the API updateAssetComputer

https://api.hornbill.com/apps/com.hornbill.servicemanager/AssetsComputer?op=updateAssetComputer

It looks to be a mix of entityUpdateRecord and entityBrowseRecord params you currently have set, the above link shows the input params available for this API and which ones are mandatory.

Kind Regards

Trevor Killick

Link to comment
Share on other sites

1 hour ago, TrevorKillick said:

@samwoo

It looks like you constructing incorrect XML for the API updateAssetComputer

https://api.hornbill.com/apps/com.hornbill.servicemanager/AssetsComputer?op=updateAssetComputer

It looks to be a mix of entityUpdateRecord and entityBrowseRecord params you currently have set, the above link shows the input params available for this API and which ones are mandatory.

Kind Regards

Trevor Killick

Thank you for that Trevor. I've gotten further now.

Write-host "$h_asset_number"
                    Write-Host "`tAsset ID:`t$h_asset_id"
                    Write-Host "`t"
                    Write-Host "`tSerial Number"
                    Write-Host "`t`tChange: $h_asset_serial_number ===> $serialNumber"
                    Write-Host "`t"

            Add-Param       "assetId" $h_asset_id
            Add-Param       "name" $h_asset_number
            Add-Param       "type" $h_asset_type
            Add-Param       "version" "1"
            Add-Param       "serialNumber" $serialNumber

            # Invoke XMLMC call, output returned as PSObject
            $xmlmcUpdate = Invoke-XMLMC "apps/com.hornbill.servicemanager/AssetsComputer" "updateAssetComputer"

            if($xmlmcUpdate.status -eq "ok") 
            {
                
                Write-Host -ForegroundColor Green "Success! Asset updated in Hornbill"
            }
            else
            {
                Write-Host -ForegroundColor Red "FAILED!"
                # API call status not OK - return status and error to console
                "API Call Status : " + $xmlmcUpdate.status
                "Error Returned  : " + $xmlmcUpdate.error
            }

I am still new to this sort of thing so apologies in advance... now i've got a different message:

Error Returned  : FlowCode Exception (com.hornbill.servicemanager/entities/AssetsComputer/fc_ops/updateAssetComputer): nodeName: Invoke Flowcode: Update Asset; nodeId: #######-####-####-##
##-############; At 152/1: "Uncaught EspMethodCall::invoke: Operation[apps/com.hornbill.servicemanager/Asset::updateAsset] FlowCode Exception (com.hornbill.servicemanager/entities/Asset/fc_
ops/updateAsset): Input parameter validation error: Non-digit characters found in the element <acqMethod>, the expected data type is 'integer'. The value was [undefined] at location '/metho
dCall/params/acqMethod'"
	throw(e);
_fc_node_exec_#######_####_####_##
##_############

It states that the field acqMethod is optional on the api page... do I still have to include this and the other optional fields in my query until I get all the way up to the SerialNumber field?

Thanks,

Samuel

Link to comment
Share on other sites

@samwoo

You shouldn't it appears to be the logic inside the updateAssetComputer API that is calling Asset::updateAsset and passing the acqMethod with undefined. I will let the application team know who can advice further. 

Kind Regards

Trevor Killick

Link to comment
Share on other sites

32 minutes ago, TrevorKillick said:

@samwoo

You shouldn't it appears to be the logic inside the updateAssetComputer API that is calling Asset::updateAsset and passing the acqMethod with undefined. I will let the application team know who can advice further. 

Kind Regards

Trevor Killick

Thanks again Trevor, i am still getting this issue after defining the "acqMethod" 1, it's now producing the same error but this time for the next parameter, actualRetireDate.

Many thanks,

Samuel

EDIT:
Interestingly, when defining the actualRetireDate = "2999-01-01 00:00:00" I run the script again, and still get the same error message, but this time for a field further down the table.... cost.

So it doesn't seem to happen for every field one after the other. Also these fields are not mandatory in the Computer Asset Class on Hornbill.

 

Link to comment
Share on other sites

Hi @samwoo

the update flowcode takes in input all the params that we pass on creation time.

So, if you need to modify only the serial number, you still need to pass all the current properties for the asset.

There is a story in the backlog to modify this behaviour and pass to the update flowcode only the modified properties.

Regards

Armando

 

 

  • Like 1
Link to comment
Share on other sites

2 minutes ago, ArmandoDM said:

Hi @samwoo

the update flowcode takes in input all the params that we pass on creation time.

So, if you need to modify only the serial number, you still need to pass all the current properties for the asset.

There is a story in the backlog to modify this behaviour and pass to the update flowcode only the modified properties.

Regards

Armando

 

 

Thank you, that makes a lot of sense. 

Can I be added to said story?

Cheers,

Samuel

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...