Jump to content

updateAssetComputer API error


Recommended Posts

Afternoon,

I'm currently writing a powershell script to sync data from our asset database (Custom MSSQL DB) in to Hornbill. I can create the devices fine but I get the following error trying to update, even if you updating it with the same data. Its talking about acqMethod but not sure where its getting that for or what field where its not getting a integer, as I compared it to the API xmlmc and any field types that are integer are integers in the object.

The version number does get incremented when trying to update. As I get the device from the API up the number and set it in the object.

 

Error and code below

FlowCode Exception (com.hornbill.servicemanager/entities/AssetsComputer/fc_ops/updateAssetComputer): nodeName: Invoke Flowcode: Update Asset; nodeId: b3817dd0-4812-4a98-9815-8b04e08bffd2; At 162/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 '/methodCall/params/acqMethod'"
        throw(e);

 

Data object for updating

serialNumber : 0123123123
type         : 18
version      : 2
os           : Windows
osVersion    : 10.0.18363.900
ownerName    : LifeOfJonny
ownerId      : LifeOfJonny@LifeOfJonny.uk
name         : WCC-XqaVwFt0Keh - 0123123123
model        : Surface Pro 6
manufacturer : Microsoft Corporation
assetId      : 8

 

Create code

Function CreateComputer {
    param ([Parameter(Mandatory=$true)]$deviceObject)
    $deviceCreated = $false
    # Build XMLMC API call    
    # params have to be in the expected order.
    Clear-Params
    Add-Param       "name" $deviceObject.name
    if ($deviceObject.ownerId -ne "")
    {
        Add-Param   "ownedById" $deviceObject.ownerId
        Add-Param   "ownedByName" $deviceObject.ownerName
        Add-Param   "ownedByType" "0"
    }
    
    Add-Param       "type" $deviceObject.type
    Add-Param       "version" $deviceObject.version
    Add-Param       "manufacturer" $deviceObject.manufacturer
    Add-Param       "model" $deviceObject.model
    Add-Param       "osType" $deviceObject.os
    Add-Param       "osVersion" $deviceObject.osVersion
    Add-Param       "serialNumber" $deviceObject.serialNumber

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

    # Read output status
    if($xmlmcOutput.status -eq "ok") {
        # Data return is correct
        $deviceCreated = $true
    } else {
        # API call status not OK - return status and error to console
        "API Call Status : " + $xmlmcOutput.status
        "Error Returned  : " + $xmlmcOutput.error
    }
    return $deviceCreated
}

 

Update Code

Function UpdateComputer {
    param ([Parameter(Mandatory=$true)]$deviceObject)
    $deviceUpdated = $false
    $deviceObject
    # Build XMLMC API call    
    # params have to be in the expected order.
    Clear-Params
    Add-Param       "assetId" $deviceObject.assetId
    Add-Param       "name" $deviceObject.name
    if ($deviceObject.ownerId -ne "")
    {
        Add-Param   "ownedById" $deviceObject.ownerId
        Add-Param   "ownedByName" $deviceObject.ownerName
        Add-Param   "ownedByType" "0"
    }
    
    Add-Param       "type" $deviceObject.type
    Add-Param       "version" $deviceObject.version
    Add-Param       "manufacturer" $deviceObject.manufacturer
    Add-Param       "model" $deviceObject.model
    Add-Param       "osType" $deviceObject.os
    Add-Param       "osVersion" $deviceObject.osVersion
    Add-Param       "serialNumber" $deviceObject.serialNumber

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

    # Read output status
    if($xmlmcOutput.status -eq "ok") {
        # Data return is correct
        $deviceUpdated = $true
    } else {
        # API call status not OK - return status and error to console
        "API Call Status : " + $xmlmcOutput.status
        "Error Returned  : " + $xmlmcOutput.error
    }
    return $deviceUpdated
}

 

Many Help would be most appreciated.

Link to comment
Share on other sites

Guest Ehsan

@LifeOfJonny,

As you've mentioned, "additionalProperties" should include attributes for the Asset class.

For example, the "Computer" Asset class includes attributes such as h_bios_manufacturer, h_bios_name, h_bios_release_date, h_bios_serial_number and h_bios_version. The "Mobile" Asset class includes attributes such as h_device_name, h_device_id, h_device_registration_state and h_phone_number.

Below, I've listed all the general properties.


    "h_acq_method": "",
    "h_actual_retired_date": "",
    "h_annual_maintenance_review_date": "",
    "h_asset_tag": "",
    "h_beneficiary": "",
    "h_booking": "",
    "h_building": "",
    "h_class": "class",
    "h_company_id": "",
    "h_company_name": "",
    "h_cost": "",
    "h_cost_center": "",
    "h_country": "",
    "h_department_id": "",
    "h_department_name": "",
    "h_deprec_method": "",
    "h_deprec_start": "",
    "h_deprec_value": "",
    "h_description": "",
    "h_disposal_code": "",
    "h_disposal_price": "",
    "h_disposal_reason": "",
    "h_floor": "",
    "h_geo_location": "",
    "h_invoice_number": "",
    "h_location": "",
    "h_location_type": "",
    "h_maintenance_cost": "",
    "h_maintenance_notice_period": "",
    "h_maintenance_termination_period": "",
    "h_maintenance_ref": "",
    "h_name": "",
    "h_notes": "",
    "h_operational_state": "",
    "h_order_date": "",
    "h_order_number": "",
    "h_product_id": "",
    "h_purpose": "",
    "h_rack": "",
    "h_received_date": "",
    "h_record_state": "",
    "h_residual_value": "",
    "h_room": "",
    "h_scheduled_retire_date": "",
    "h_site_id": "",
    "h_site": "",
    "h_static": "",
    "h_substate_id": "",
    "h_substate_name": "",
    "h_supplier_contract": "",
    "h_supplier_id": "",
    "h_supported_by": "",
    "h_type": "",
    "h_u_height": "",
    "h_u_position": "",
    "h_version": "",
    "h_warranty_expires": "",
    "h_warranty_start": ""
}

I hope this helps.

Ehsan

Link to comment
Share on other sites

Guest Ehsan

The JSON property needs to include attribute names, rather than the database column name. Below, I've posted all the attributes and their mapping to the database columns.

"general" : {
                "h_acq_method": "acqMethod",
                "h_actual_retired_date": "actualRetireDate",
                "h_annual_maintenance_review_date": "annualMaintenanceReviewDate",
                "h_asset_tag": "assetTag",
                "h_beneficiary": "beneficiary",
                "h_booking": "booking",
                "h_building": "building",
                "h_class": "class",
                "h_company_id": "companyId",
                "h_company_name": "companyName",
                "h_cost": "cost",
                "h_cost_center": "costCenter",
                "h_country": "country",
                "h_department_id": "departmentId",
                "h_department_name": "departmentName",
                "h_deprec_method": "deprecMethod",
                "h_deprec_start": "deprecStart",
                "h_deprec_value": "deprecValue",
                "h_description": "description",
                "h_disposal_code": "disposalCode",
                "h_disposal_price": "disposalPrice",
                "h_disposal_reason": "disposalReason",
                "h_floor": "floor",
                "h_geo_location": "geoLocation",
                "h_invoice_number": "invoiceNumber",
                "h_location": "location",
                "h_location_type": "locationType",
                "h_maintenance_cost": "maintenanceCost",
                "h_maintenance_notice_period": "maintenanceNoticePeriod",
                "h_maintenance_termination_period": "maintenanceTerminationPeriod",
                "h_maintenance_ref": "maintenanceRef",
                "h_name": "name",
                "h_notes": "notes",
                "h_operational_state": "operationalState",
                "h_order_date": "orderDate",
                "h_order_number": "orderNumber",
                "h_product_id": "productId",
                "h_purpose": "purpose",
                "h_rack": "rack",
                "h_received_date": "receivedDate",
                "h_record_state": "state",
                "h_residual_value": "residualValue",
                "h_room": "room",
                "h_scheduled_retire_date": "scheduledRetireDate",
                "h_site_id": "siteId",
                "h_site": "site",
                "h_static": "static",
                "h_substate_id": "substateId",
                "h_substate_name": "substateName",
                "h_supplier_contract": "supplierContract",
                "h_supplier_id": "supplierId",
                "h_supported_by": "supportedBy",
                "h_type": "type",
                "h_u_height": "uHeight",
                "h_u_position": "uPosition",
                "h_version": "version",
                "h_warranty_expires": "warrantyExpires",
                "h_warranty_start": "warrantyStart"
            },
            "basic": {
                "h_type": "type",
                "h_name": "name",
                "h_description": "description",
                "h_dsc_fingerprint": "swDscFingerprint",
                "h_dsc_first_discovered": "swDscFirstDiscovered",
                "h_dsc_last_changed": "swDscLastChanged",
                "h_dsc_last_discovered": "swDscLastDiscovered",
                "h_dsc_siid": "swDscSiid",
                "h_dsc_source": "swDscSource"
            },
            "computer" : {
                "h_bios_manufacturer": "biosManufacturer",
                "h_bios_name": "biosName",
                "h_bios_release_date": "biosReleaseDate",
                "h_bios_serial_number": "biosSerialNumber",
                "h_bios_version": "biosVersion",
                "h_cpu_clock_speed": "cpuClockSpeed",
                "h_cpu_info": "cpuInfo",
                "h_description": "description",
                "h_disaster_recovery": "disasterRecovery",
                "h_dsc_cf_fingerprint": "dscCfFingerprint",
                "h_dsc_first_discovered": "dscFirstDiscovered",
                "h_dsc_hw_fingerprint": "dscHwFingerprint",
                "h_dsc_last_changed": "dscLastChanged",
                "h_dsc_last_discovered": "dscLastDiscovered",
                "h_dsc_net_fingerprint": "dscNetFingerprint",
                "h_dsc_os_fingerprint": "dscOsFingerprint",
                "h_dsc_siid": "dscSiid",
                "h_dsc_source": "dscSource",
                "h_dsc_sw_fingerprint": "dscSwFingerprint",
                "h_environment": "environment",
                "h_last_logged_on": "lastLoggedOn",
                "h_last_logged_on_user": "lastLoggedOnUser",
                "h_last_patch_date": "lastPatchDate",
                "h_logical_cpus": "logicalCpus",
                "h_mac_address": "macAddress",
                "h_manufacturer": "manufacturer",
                "h_max_memory_capacity": "maxMemoryCapacity",
                "h_memory_info": "memoryInfo",
                "h_model": "model",
                "h_monitoring": "monitoring",
                "h_monitoring_software": "monitoringSoftware",
                "h_name": "name",
                "h_net_computer_name": "netComputerName",
                "h_net_ip_address": "netIpAddress",
                "h_net_name": "netName",
                "h_net_win_dom_role": "netWinDomRole",
                "h_net_win_domain": "netWinDomain",
                "h_next_patch_date": "nextPatchDate",
                "h_number_memory_slots": "numberMemorySlots",
                "h_optical_drive": "opticalDrive",
                "h_os_description": "osDescription",
                "h_os_registered_to": "osRegisteredTo",
                "h_os_serial_number": "osSerialNumber",
                "h_os_service_pack": "osServicePack",
                "h_os_type": "osType",
                "h_os_version": "osVersion",
                "h_physical_cores": "physicalCores",
                "h_physical_cpus": "physicalCpus",
                "h_physical_disk_size": "physicalDiskSize",
                "h_private_ip_address": "privateIpAddress",
                "h_public_ip_address": "publicIpAddress",
                "h_serial_number": "serialNumber",
                "h_subnet_mask": "subnetMask",
                "h_type": "type",
                "h_watts": "watts",
                "h_wmac_address": "wmacAddress"
            },
            "software": {
                "h_dsc_fingerprint": "swDscFingerprint",
                "h_dsc_first_discovered": "swDscFirstDiscovered",
                "h_dsc_last_changed": "swDscLastChanged",
                "h_dsc_last_discovered": "swDscLastDiscovered",
                "h_dsc_siid": "swDscSiid",
                "h_dsc_source": "swDscSource",
                "h_vendor_id": "swVendorId",
                "h_vendor_name": "swVendorName",
                "h_product_id": "swProductId",
                "h_product_name": "swProductName",
                "h_version": "swVersion",
                "h_version_name": "swVersionName",
                "h_registered_email_address": "registeredEmailAddress",
                "h_registered_name": "registeredName",
                "h_license_key": "licenseKey",
                "h_license_start_date": "licenseStartDate",
                "h_license_expiry_date": "licenseExpiryDate",
                "h_license_renewal_date": "licenseRenewalDate",
                "h_license_type": "licenseType",
                "h_license_cost": "licenseCost",
                "h_release_date": "releaseDate",
                "h_description": "description",
                "h_name": "name",
                "h_type": "type"
            },
            "computerPeripheral": {
                "h_connection_types": "connectionTypes",
                "h_wireless": "wireless",
                "h_manufacturer": "manufacturer",
                "h_serial_number": "serialNumber",
                "h_model": "model",
                "h_description": "description",
                "h_name": "name",
                "h_type": "type"
            },
            "mobileDevice": {
                "h_device_name": "deviceName",
                "h_device_id": "deviceId",
                "h_device_registration_state": "deviceRegistrationState",
                "h_phone_number": "phoneNumber",
                "h_compliance_state": "complianceState",
                "h_compliance_expiration": "complianceExpiration",
                "h_device_encrypted": "deviceEncrypted",
                "h_enrolled": "enrolled",
                "h_last_sync": "lastSync",
                "h_mtpas_access_class": "mtpasAccessClass",
                "h_manufacturer": "manufacturer",
                "h_model": "model",
                "h_capacity": "capacity",
                "h_imei_number": "imeiNumber",
                "h_imsi_number": "imsiNumber",
                "h_serial_number": "serialNumber",
                "h_sim_number": "simNumber",
                "h_sim_type": "simType",
                "h_cpu_info": "cpuInfo",
                "h_ip_address": "ipAddress",
                "h_mac_address": "macAddress",
                "h_os_description": "osDescription",
                "h_os_version": "osVersion",
                "h_os_patch": "osPatch",
                "h_description": "description",
                "h_name": "name",
                "h_type": "type"
            },
            "networkDevice": {
                "h_mac_address": "macAddress",
                "h_net_ip_address": "netIpAddress",
                "h_telnet_enabled": "telnetEnabled",
                "h_ssh_enabled": "sshEnabled",
                "h_http_enabled": "httpEnabled",
                "h_model": "model",
                "h_manufacturer": "manufacturer",
                "h_serial_number": "serialNumber",
                "h_physical_cpus": "physicalCpus",
                "h_physical_cores": "physicalCores",
                "h_power_supply_count": "powerSupplyCount",
                "h_watts": "watts",
                "h_weight": "weight",
                "h_physical_disk_size": "physicalDiskSize",
                "h_net_device_version": "netDeviceVersion",
                "h_username": "username",
                "h_backed_up": "backedUp",
                "h_description": "description",
                "h_name": "name",
                "h_type": "type"
            },
            "printer": {
                "h_average_pages_per_minute": "averagePagesPerMinute",
                "h_dsc_cf_fingerprint":"dscCfFingerprint",
                "h_dsc_first_discovered":"dscFirstDiscovered",
                "h_dsc_hw_fingerprint":"dscHwFingerprint",
                "h_dsc_last_changed":"dscLastChanged",
                "h_dsc_last_discovered":"dscLastDiscovered",
                "h_dsc_net_fingerprint":"dscNetFingerprint",
                "h_dsc_siid":"dscSiid",
                "h_dsc_source":"dscSource",
                "h_dsc_sw_fingerprint":"dscSwFingerprint",
                "h_horizontal_resolution":"horizontalResolution",
                "h_image_fuser":"imageFuser",
                "h_image_transfer_roller":"imageTransferRoller",
                "h_languages": "languages",
                "h_manufacturer": "manufacturer",
                "h_marking_technology": "markingTechnology",
                "h_model": "model",
                "h_number_of_trays": "numberOfTrays",
                "h_paper_sizes": "paperSizes",
                "h_port": "port",
                "h_printer_capabilities": "printerCapabilities",
                "h_serial_number": "serialNumber",
                "h_vertical_resolution": "verticalResolution",
                "h_net_ip_address": "netIpAddress",
                "h_net_mac_address": "netMacAddress",
                "h_wmac_address": "wmacAddress",
                "h_toner_code_black": "tonerCodeBlack",
                "h_toner_code_cyan": "tonerCodeCyan",
                "h_toner_level_black": "tonerLevelBlack",
                "h_toner_level_cyan": "tonerLevelCyan",
                "h_quantity_in_stock_black": "quantityInStockBlack",
                "h_quantity_in_stock_cyan": "quantityInStockCyan",
                "h_toner_code_magenta": "tonerCodeMagenta",
                "h_toner_code_yellow": "tonerCodeYellow",
                "h_toner_level_magenta": "tonerLevelMagenta",
                "h_toner_level_yellow": "tonerLevelYellow",
                "h_quantity_in_stock_magenta": "quantityInStockMagenta",
                "h_quantity_in_stock_yellow": "quantityInStockYellow",
                "h_image_fuser": "imageFuser",
                "h_image_transfer_roller": "imageTransferRoller",
                "h_description": "description",
                "h_name": "name",
                "h_type": "type"
            },
            "telecoms": {
                "h_phone_number": "phoneNumber",
                "h_extension": "extension",
                "h_ip_address": "ipAddress",
                "h_mac_address": "macAddress",
                "h_wmac_address": "wmacAddress",
                "h_manufacturer": "manufacturer",
                "h_serial_number": "serialNumber",
                "h_model": "model",
                "h_description": "description",
                "h_name": "name",
                "h_type": "type"
            }

 

As an example, if you wanted to update h_last_logged_on column for a "Computer" Asset, you would set additionalProperties to the below:

[{"name":"lastLoggedOn","value":"2020-07-14 12:00:00"}]

You could use updateAssetComputer but this API was not designed to update specified columns for an Asset. The API requires you to pass in the current value for each attribute in the Asset record as well as those you wanted to update. To address this design flaw, a new API called updateAsset2 was introduced so that you only pass in the values that you wish to update.

Link to comment
Share on other sites

Guest Ehsan

@LifeOfJonny,

Yes, that's required.

The options are basic, computer, software, software, computerPeripheral, mobileDevice, networkDevice, printer and telecoms.

Ehsan

Link to comment
Share on other sites

1 minute ago, Ehsan said:

@LifeOfJonny,

Yes, that's required.

The options are basic, computer, software, software, computerPeripheral, mobileDevice, networkDevice, printer and telecoms.

Ehsan

Thanks for confirming, as the API says its optional, but as you say its actually required ^_^

Link to comment
Share on other sites

I'm trying to write code to use updatemethod2, but its bit tricky when I want to pass a value to be updated to a updateAsset function and the field doesn't know if its a generalProperties or additionalProperties.

I basically retrieve my using getAssetsFiltered, to get the exact asset I'm after, which returns the data as a json array. but it does not report where the values belongs (generalProperties or additionalProperties)

How would you recommend going forward? Do I do one update per field changed field, this way I can control where there value goes in to generalProperties or additionalProperties. Ideally I want to create an array of values that have changed, and then throw that in to the function and it to then update the asset. Don't really want to be doing 3/4 calls to change 3/4 fields.

Link to comment
Share on other sites

Guest Ehsan

@LifeOfJonny,

The general information for Assets are held in h_cmdb_assets table. The properties for the "computer" Asset type is held in h_cmdb_assets_computer table. You'll need to be able to distinguish between a column in the general Asset information and extended Asset information.

An Asset will have only one Asset type (i.e. value for h_class column), so you'll only need to make one API call per Asset?

Would you not be able to use the JSON object I provided to build your code? The Asset type (i.e. class) is available to you for the Asset?

 

 

 

Link to comment
Share on other sites

I was thinking of building an array of hornbillAttribName and new value of any that had changed you see.

So what your saying is I need to hardcode the field mappings between generalProperties or additionalProperties to update the array of values?

Link to comment
Share on other sites

Guest Ehsan

@LifeOfJonny Yes, I would suggest for you to go with that. Any enhancements to the Assets functionality is published on the release notes. There's an enhancement request coming up in the coming months where we'll add new columns but either than that, we don't add columns every so often as we've considered the majority of the industry standard Assets related columns.

Link to comment
Share on other sites

23 hours ago, Ehsan said:

@LifeOfJonny Yes, I would suggest for you to go with that. Any enhancements to the Assets functionality is published on the release notes. There's an enhancement request coming up in the coming months where we'll add new columns but either than that, we don't add columns every so often as we've considered the majority of the industry standard Assets related columns.

Gotten it working but how do I update owned_by its not on your list? or do I need to call different method to change that?

Jonny

Link to comment
Share on other sites

Guest Ehsan

@LifeOfJonny,

Ah yes it isn't, it looks like the API requires separate back-end changes for that attribute.

Here's an example when updating the owner of a mobile device Asset.

<methodCall service="apps/com.hornbill.servicemanager/Asset" method="updateAsset2">

        <params>

                <assetId>4</assetId>

                <assetClass>mobileDevice</assetClass>

                <generalProperties>[{"name":"ownedById","value":"ehsans"},{"name":"ownedByName","value":"Ehsan"},{"name":"ownedByType","value":0},{"name":"sourceImage","value":""}]</generalProperties>

        </params>

</methodCall>

The same applies to when updating the Used By attribute. Example as below.

<methodCall service="apps/com.hornbill.servicemanager/Asset" method="updateAsset2">

        <params>

                <assetId>4</assetId>

                <assetClass>mobileDevice</assetClass>

                <generalProperties>[{"name":"usedById","value":"ehsans"},{"name":"usedByName","value":"Ehsan"},{"name":"usedByType","value":0},{"name":"sourceImage","value":""}]</generalProperties>

        </params>

</methodCall>

Link to comment
Share on other sites

  • 6 months later...
On 7/9/2020 at 2:50 PM, LifeOfJonny said:

Gotten it working but how do I update owned_by its not on your list? or do I need to call different method to change that?

Jonny

Hi @Jonny and all,

I was wondering if you could provide a bit of information on how you got this working.  I am trying to use updateAsset2 API and have the following function that should allow me to do what I need it to do:

function Update-HB-Asset2 
{
    [CmdletBinding()]
    param 
    (
        # The ID of the Asset that will be updated
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [Int] $asset_ID,

        # The Class of the Asset that will be updated
        # (computer, software, software, computerPeripheral, mobileDevice, networkDevice, printer and telecoms)
        [Parameter(Mandatory=$true)]
        [ValidateSet("computer", "software", "computerPeripheral", "mobileDevice", "networkDevice", "printer", "telecoms")]
        [String] $asset_Class,

        # OPTIONAL: The new name of the Asset
        [String] $asset_Name,

        # OPTIONAL: The Operational State of the Asset
        # ( 0=operational, 1=pre-production, 2=retired )
        [ValidateSet("operational","pre-production","retired")]
        [String] $asset_OperationalState
    )

    #$OutputEncoding = [System.Text.Encoding]::Default

    # =============================================================
    # Process General Asset details
    # =============================================================
    
        # =============================================================
        # Prepare Hastable collection
        # =============================================================
        $Asset_General = @{}

        # =============================================================
        # Asset Name
        # =============================================================
        if($asset_Name)
        {
            $Asset_General += @{'name' = "$asset_Name"}
        }

        # =============================================================
        # Asset Operational State
        # =============================================================
        if($asset_OperationalState) 
        { 
            switch ($asset_OperationalState)
            {
                'operational' { $Asset_General += @{'operationalState' = "0"}  }
                'pre-production' { $Asset_General += @{'operationalState' = "1"}  }
                #'pre-production' { $Asset_General += @{'operationalState' = "pre-production"}  }
                'retired' { $Asset_General += @{'operationalState' = "2"}  }
            }
            
        }

        # =============================================================
        # Convert Hastable collection to JSON
        # =============================================================
        #$Asset_General_JSON = ConvertTo-Json $Asset_General 
        #$Asset_General_JSON = "[" + ($Asset_General | ConvertTo-Json -Compress ) + "]" | % { [System.Text.RegularExpressions.Regex]::Unescape($_) } 
        $Asset_General_JSON = ConvertTo-Json $Asset_General | % { [System.Text.RegularExpressions.Regex]::Unescape($_) }

    # =============================================================
    # Exit script if nothing has been defined
    # =============================================================
    if($null -eq $Asset_General -and $null -eq $Asset_Additional)
    {
        exit
    }

    # =============================================================
    # Build the API call
    # =============================================================
    Clear-HB-Params

    Add-HB-Param "assetId"          "$asset_ID"
    Add-HB-Param "assetClass"       "$asset_Class"

    if($Asset_General) 
    {
        Add-HB-Param "generalProperties"        $Asset_General_JSON
    }

    $xmlmc = Invoke-HB-XMLMC "apps/com.hornbill.servicemanager/Asset" "updateAsset2"

    Return $xmlmc.Params
}

Whenever I run the above, the query completes successfully result in the AssetID returning, but when I check the Logs in Hornbill, I can see this attempt was made, but the generalProperties which should be populated from the JSON is not used at all.

When I check $Asset_General_JSON it looks right

{
    "operationalState":  "pre-production"
}

When I check Get-HB-Params, I get the following which doesn't look right in the JSON part

<params>
  <assetId>12995</assetId>
  <assetClass>computer</assetClass>
  <generalProperties>{
    &quot;operationalState&quot;:  &quot;pre-production&quot;
}</generalProperties>
</params>

The goal of the function is to make all Asset Fields updateable, but optional (obviously it all depends on the Asset Class), meaning if you don't enter a value then that field won't be updated in Hornbill using the API.  The first one I wanted to do was to just update the Operational State against one particular Asset.

What did you managed to do to achieve your goal with this in PowerShell?

Thanks,

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...