Jump to content

Asset Update and Data Validation


Recommended Posts

I'm trying to carry out a simple asset update of a Computer Peripheral and it's proven quite hard work. I only want to change the "location" of the asset.

In order to achieve success I couldn't just submit the "required" fields as the FlowCode refused to validate the data that must already be part of the record. So I have had to populate all kinds of other fields to get it to work.

Required fields are: assetId, name, type, version

But I actually had to fill in all of these.

        $peripheral = [
            'acqMethod' => 1,
            'actualRetireDate' => '1970-01-01 00:00:00',
            'assetId' => 3533,
            'cost' => 0,
            'deprecMethod' => 0,
            'deprecStart' => '1970-01-01 00:00:00',
            'deprecValue' => 0,
            'disposalPrice' => 0,
            'location' => 'Bedroom',
            'locationType' => 0,
            'maintenanceCost' => 0,
            'maintenanceRef' => '',
            'name' => 'CBC8522',
            'operationalState' => 0,
            'orderDate' => '1970-01-01 00:00:00',
            'receivedDate' => '1970-01-01 00:00:00',
            'residualValue' => 0,
            'scheduledRetireDate' => '1970-01-01 00:00:00',
            'siteId' => 1,
            'sourceImage' => '',
            'state' => 0,
            'type' => 8, //'Monitor',
            'version' => 0,
            'warrantyExpires' => '1970-01-01 00:00:00',
            'warrantyStart' => '1970-01-01 00:00:00',
            'wireless' => ''
        ];

Which produces the XML:

<methodCall service="apps/com.hornbill.servicemanager/AssetsComputerPeripheral" method="updateAssetComputerPeripheral"><params>
  <acqMethod>1</acqMethod>
  <actualRetireDate>1970-01-01 00:00:00</actualRetireDate>
  <assetId>3533</assetId>
  <cost>0</cost>
  <deprecMethod>0</deprecMethod>
  <deprecStart>1970-01-01 00:00:00</deprecStart>
  <deprecValue>0</deprecValue>
  <disposalPrice>0</disposalPrice>
  <location>Bedroom</location>
  <locationType>0</locationType>
  <maintenanceCost>0</maintenanceCost>
  <maintenanceRef></maintenanceRef>
  <name>CBC8522</name>
  <operationalState>0</operationalState>
  <orderDate>1970-01-01 00:00:00</orderDate>
  <receivedDate>1970-01-01 00:00:00</receivedDate>
  <residualValue>0</residualValue>
  <scheduledRetireDate>1970-01-01 00:00:00</scheduledRetireDate>
  <siteId>1</siteId>
  <sourceImage></sourceImage>
  <state>0</state>
  <type>8</type>
  <version>0</version>
  <warrantyExpires>1970-01-01 00:00:00</warrantyExpires>
  <warrantyStart>1970-01-01 00:00:00</warrantyStart>
  <wireless></wireless>
</params></methodCall>

I can understand the validation reasoning, but it would seem that all this is bypassed during the asset import process, which is probably going to leave a minefield for later. My only recourse would be to search for the asset, retrieve all the current values, validate them locally and populate them where necessary, then resubmit the data just to update the one field I want to update.

If the fields aren't set as mandatory surely the flowcode shouldn't be acting like this?

Link to comment
Share on other sites

Further to this it's become really quite a major issue.

The call to apps/com.hornbill.servicemanager/Asset::updateAsset may not require much more than those field above to validate, but if you don't provide the parameters they get wiped out. So it's not a real update - you have to read ALL the parameters from an existing asset only to write them ALL back. If you don't the fields become the string 'undefined'.

I did some asset updates using just the parameter above and the description, asset tag and name all became 'undefined'. Not at all useful.

So in any form submission I have to call entityGetRecord, scrape all the data to add it back to the submitted data or it's gone. :( I really don't want to fetch all that data to the end-user form for them to submit in hidden fields, so all the additional processing has to be done before actually calling updateAsset.

capture.png

Link to comment
Share on other sites

Thanks for post Bob320,

Currently as you have identified the only way to perform the updates via the flowcode is to get the existing record data and then supply all populated data fields to the update even if you only want to update a single field, this is the way it is currently used within the application where we do supply all of the relevant data fields on updates.

I would agree that the flowcode parameter validation does not make much sense when other values do need to be supplied to prevent data loss, therefore I have raised a problem for the development team (REF: PM00142915) to address the validation and also review if any improvements can be made to the flowcodes to remove the need to supply the array of extra values when only performing an update on a specific field.

Regards,

David.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

I've continued with this process and ran aground on trying to read all of the asset data before re-writing it back including the columns I've modified. It's not looking at all straight forward.

I tried to see how the SM update process works and can't put together how to carry out a similar process. Looking at the calls that are made when viewing an asset it calls data/getEntityRecord - which I thought would resolve this issue for me. So using the same call I retrieve the asset.

Here's the changes I submitted and the now updated asset record ready to write back:

array:5 [▼
  "h_pk_asset_id" => "9398"
  "h_used_by" => ""
  "h_site" => "LEICS Off Site"
  "h_location" => "Field Worker"
  "h_location_type" => "0"
]

{#379 
  +"h_pk_asset_id": "9398"
  +"h_acq_method": "1"
  +"h_actual_retired_date": "1970-01-01 00:00:00"
  +"h_asset_tag": "CBC2471"
  +"h_class": "computer"
  +"h_cost": "0.000000000000000"
  +"h_cost_center": "V002"
  +"h_country": "AF"
  +"h_created_date": "2016-09-13 13:04:38"
  +"h_deprec_method": "0"
  +"h_deprec_start": "1970-01-01 00:00:00"
  +"h_deprec_value": "0.000000000000000"
  +"h_description": "P II 350 Pentium"
  +"h_disposal_price": "0.000000000000000"
  +"h_idx_ref": "lid_2b217cd5-0924-48db-99ff-c873aae0d5d5"
  +"h_last_updated": "2016-09-17 09:33:57"
  +"h_last_updated_by": "paulb"
  +"h_location": "Field Worker"
  +"h_location_type": "0"
  +"h_maintenance_cost": "0.000000000000000"
  +"h_name": "CBC2471"
  +"h_operational_state": "2"
  +"h_order_date": "1999-01-26 12:00:00"
  +"h_order_number": "UNKNOWN"
  +"h_received_date": "1970-01-01 00:00:00"
  +"h_record_state": "0"
  +"h_substate_id": "-1"
  +"h_residual_value": "0.000000000000000"
  +"h_scheduled_retire_date": "1970-01-01 00:00:00"
  +"h_site_id": "-1"
  +"h_supplier_id": "UNKNOWN"
  +"h_type": "2"
  +"h_version": "1"
  +"h_warranty_expires": "1970-01-01 01:00:00"
  +"h_warranty_start": "1970-01-01 00:00:00"
  +"h_company_id": "-1"
  +"h_used_by": ""
  +"h_site": "LEICS Off Site"
}

But, it turns out that to write back that asset I must now change all of the column names as writing them is different to reading. :o

eg. `h_pk_asset_id` becomes `assetId`, `h_asset_tag` becomes `assetTag`,

Well that's more than a little frustrating. I now have to create a lookup AND ensure that I construct the object in the correct order for writing as reading them in the order above doesn't match the order in which they are written back. eg. `acqMethod` comes first in the written object, but second in the read object.

But what I also notice is that the read object is also missing a lot of the columns listed in the write object. So it looks like `getEntityRecord` isn't retrieving all of the asset record. eg. there is no `companyName` in the data returned. So is `getEntityRecord` only returning columns with values, or only a subset of the record? How do I go about reading everything so I can write everything back?

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