Jörg Walther Posted February 7 Share Posted February 7 Hi All, We have several hundred assets incorrectly imported as type 'desktop'. Is there a way we can bulk change these records to a more appropriate type of 'laptop'? The ui doesn't let you change it and if you use asset_import.exe it creates a separate, additional entry. We're currently in the process of reviving and improving our usage of Hornbill for assets, so would like to rectify this incorrect type. Some of these assets have linked requests, but our use of hornbill for assets so far has been very inconsistent. In the worst case we'd consider deleting these entries and starting from scratch with a sustainable import and update method. Though in that case we'd come against being unable to delete the records due to the fact they're already linked to requests. Any suggestions would be much appreciated, Kind regards, Jörg Link to comment Share on other sites More sharing options...
CraigP Posted February 7 Share Posted February 7 I'm not sure if there is a simpler way within the UI but I've had success using the updateAsset2 API to script a bulk update to the types of multiple assets in the past (as long as the new type is still within the same asset class). Link to comment Share on other sites More sharing options...
SamS Posted February 7 Share Posted February 7 Hi @Jörg Walther, There is indeed no easy way of doing it - ideally the mistake/categorisation doesn't happen in the first place. I am aware that our specialists can likely(*) do it for you, though that will be chargeable - you will have to go through your account manager/CS contact. (*) a few caveats exist Link to comment Share on other sites More sharing options...
Jörg Walther Posted February 7 Author Share Posted February 7 Thanks @CraigP I'll have a look at the API. Also thanks @SamS I think I'll either, hopefully be able to resolve it with the above APO or we'll look at starting from scratch. Link to comment Share on other sites More sharing options...
Jörg Walther Posted February 7 Author Share Posted February 7 Unfortunately I can't make heads or tails from the documentation. It may be sufficient if you're well versed and work lots with API, but I'm not. I'm struggling with the general approach and a lot with syntax. So, for example is 'type' a generalProperties or additionalProperties. Does this correlate with AssetGenericFieldMapping and AssetTypeFieldMapping? Does that cover AssetType, type or h_type at all? If so what syntax does the "JSON string of the properties to use to populate the asset details" take, what does it look like for a single item. The Powershell version certainly doesn't seem happy with anything like generalProperties = "xs:h_type: Laptop", "xs:"h_type": "Laptop"" or "xs:'h_type': 'Laptop'" 1 Link to comment Share on other sites More sharing options...
CraigP Posted February 8 Share Posted February 8 The JSON to only update the type looks like this ("2" in this case being whatever the ID of the asset type you want to update them to): [{ "name": "type", "value": "2" }] It goes in the General Properties parameter. I agree that the documentation could be improved. Code examples are nice, but they don't have actual examples of the format/syntax that certain parameters require. Link to comment Share on other sites More sharing options...
Jörg Walther Posted February 8 Author Share Posted February 8 Thanks Craig! Hopefully we're starting to get there, so your suggestion's much appreciated! Though I'm still unsure how this fits into the scriptlet suggested by the documentation for doing this in PowerShell (yes, that's how I rock ) . Firstly the ID is then mentioned twice, in assetId and generalProperties. If that's how it works, ok, though confusing. Secondly PowerShell really isn't happy about the syntax, see error example and script screenshot (attached). Error: At line:9 char:36 + "name": "type", + ~~~~~~~~~~~~~~~ Unexpected token 'name": "type", "value": "8291"}] "' in expression or statement. Anything obvious I'm doing wrong? I appreciate that code examples have serious limitations, there's just too many possible variations of how it may be used. But I often find even one or two examples useful as a very basic indication of which direction to go. Link to comment Share on other sites More sharing options...
CraigP Posted February 9 Share Posted February 9 Hi @Jörg Walther So the ID that goes in the general properties is the type ID you want to update the asset to, not the asset ID e.g. If you want to update the asset type to Laptop, then it is whatever the type ID for Laptop is for on your instance (I'm not sure if 2 is the default type ID for Laptop on all Hornbill instances?). You can check the type ID for your instance in the h_cmdb_asset_types table. The reason for the error is that you're encapsulating the string with double quotes, but the JSON string requires double quotes inside so it's getting confused where the string starts and ends. I think if you simply replace the double quotes around the string with single quotes then it should sort it. generalproperties = '[{ "name": "type", "value": "2" }]' Alternatively you can create an object first and then convert it to a JSON string, and then feed that string into generalproperties. Assuming you wanting to convert the Desktop asset with Asset ID 8291 to Laptop, and the Laptop type is ID 2 on your instance, then that would probably look something like this (not tested): $JSONhash = [ordered]@{"name"="type";"value"=2} $JSON = $JSONhash | ConvertTo-Json $JSON = "[$JSON]" $Body = @{ "@service" = "apps/com.hornbill.servicemanager/Asset" "@method" = "updateAsset2" params = @{ assetId = "8291" assetClass = "computer" generalProperties = $JSON } } A few side notes: I'm not familiar why "xs" is at the start of the strings. I've not personally done this so think it's safe to remove. You're not updating any additional properties, so this parameter isn't required. Link to comment Share on other sites More sharing options...
Jörg Walther Posted February 13 Author Share Posted February 13 Thanks again all for your help here. It's much appreciated. However I decided to delete the incorrect assets using the hornbillCleaner utility, which worked well. I struggled for quite some time but despite your help could not get the Invoke-RestMethod, nor the HornbillAPI Invoke-HB-XMLMC method working. I tried your suggestions and at every error attempted a few variations, but nothing worked. In order to get our project to progress I decided to start from scratch. This brand new import from the snow d/b has since worked well. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now