Hide asset fields

Hi all

Am trying to figure out a way to hide a paragraph for assets. The case is that a customer wants to add secret instructions over how to use certain assets.

On this image I want to try to hide the “Secret Paragraph” as this should only be displayed to a certain group witihin the workspace?

In this case the Secret Paragraph is something I added as a custom_field from admin view.

My plan is to build a placeholder asset sidebar app that will let the user do CRUD operations on this field.

From what I can see it is possible to hide different UI elements, however it is mostly on the Tickets page?

https://developers.freshworks.com/docs/app-sdk/v2.3/freshservice/front-end-apps/interface-methods/

Adding this thread as well, as it turns out to be a showstopper for us.

Hi @Ansfs91. May have to think a bit out of the box. “Secret” from whom? Who shouldn’t see the data in FS? Data could be stored in the app, a KB, or externally and just associated with the asset and manage your CRUD.

Hi @Ansfs91. Looking at the link to the other thread to get more context, this is possible today. The custom fields are known as Type Fields in Assets. If we create a custom field under the Computer layer:

The fields are named with the layer id, which can be queried here or via the URL. These layers and ID are unique to each instance, so these steps will need to reproduced in the instance you are developing for. To confirm the field, start by using the Get Asset Type endpoint and then fields can be retrieved for that layer (example using the FreshservicePS Powershell module):

Get the Asset Layer for Computer:

PS C:\Build> Get-FSAssetType | Where{$_.name -eq 'Computer'}

id                   : 21000855272
name                 : Computer
parent_asset_type_id : 21000855267
visible              : True
description          : 
created_at           : 8/29/2022 2:17:36 PM
updated_at           : 8/29/2022 2:17:36 PM

Get the fields for the Computer layer. It will contain all of the layers and we need to parse the fields for the Computer layer:

PS C:\Build> $fields = Get-FSAssetType -id 21000855272 -fields
PS C:\Build> $fields | WHere{$_.field_header -eq 'Computer'} | Select -ExpandProperty fields      

id            : 21003895869
created_at    : 8/29/2022 2:17:42 PM
updated_at    : 8/29/2022 2:17:42 PM
asset_type_id : 21000855272
name          : os_21000855272
label         : OS
required      : False
is_unique     : False
field_type    : dropdown
data_type     : string
default_field : True
choices       : {Windows Windows, Linux Linux, Mac Mac, Solaris Solaris…}

...

id            : 21013769414
created_at    : 1/2/2024 4:27:02 PM
updated_at    : 1/2/2024 4:27:02 PM
asset_type_id : 21000855272
name          : secret_squirrel_21000855272
label         : Secret Squirrel
required      : False
is_unique     : False
field_type    : paragraph
data_type     : text
default_field : False

Then we just need to set the Type Fields on the asset:

PS C:\Build> Set-FSAsset -id 3674 -type_fields @{secret_squirrel_21000855272 = 'This is a test of the secret squirrel network'} -Verbose
VERBOSE: Processing body parameter type_fields
VERBOSE: Performing the operation "Set-FreshServiceAsset" on target "https://its-fine.freshservice.com/api/v2/assets/3674".
VERBOSE: Appending Authorization header
VERBOSE: Invoke-FreshworksRestMethod - Initiating REST API call to https://its-fine.freshservice.com/api/v2/assets/3674 with API key:  XXX
VERBOSE: Invoke-FreshworksRestMethod - REST call parameters:
VERBOSE: Invoke-FreshworksRestMethod - Uri:  https://its-fine.freshservice.com/api/v2/assets/3674
VERBOSE: Invoke-FreshworksRestMethod - Body:  {
  "type_fields": {
    "secret_squirrel_21000855272": "This is a test of the secret squirrel network"
  }
}
VERBOSE: Invoke-FreshworksRestMethod - ErrorAction:  Stop
VERBOSE: Invoke-FreshworksRestMethod - ContentType:  application/json; charset=utf-8
VERBOSE: Invoke-FreshworksRestMethod - Headers:
VERBOSE: Invoke-FreshworksRestMethod - Authorization:  Basic XXX
VERBOSE: Invoke-FreshworksRestMethod - Accept-Charset:  utf-8
VERBOSE: Invoke-FreshworksRestMethod - Method:  PUT
VERBOSE: Invoke-FreshworksRestMethod - UseBasicParsing:  True
VERBOSE: Invoke-FreshworksRestMethod - Invoking REST PUT Method on https://its-fine.freshservice.com/api/v2/assets/3674...
VERBOSE: Invoke-FreshworksRestMethod - Forcing TLS 1.2 protocol for invoking REST method.
VERBOSE: Requested HTTP/1.1 PUT with 113-byte payload
VERBOSE: Received HTTP/1.1 response of content type application/json of unknown size
VERBOSE: Returned status OK with code 200.
VERBOSE: Current FreshService minute rate limit is 160 with 159 calls remaining (0.62% used) .
VERBOSE: Invoke-FreshworksRestMethod - Completed REST PUT Method on https://its-fine.freshservice.com/api/v2/assets/3674 in 00:00:00.6625268.
VERBOSE: Returning asset property with count 1

attachments       : {}
cloud_files       : {}
type_fields       : @{product_21000855267=21000056898; vendor_21000855267=; cost_21000855267=; warranty_21000855267=; acquisition_date_21000855267=; warranty_expiry_date_21000855267=; domain_21000855267=; asset_state_21000855267=In Use; serial_number_21000855267=; last_audit_date_21000855267=; os_21000855272=; os_version_21000855272=; os_service_pack_21000855272=; memory_21000855272=; disk_space_21000855272=; 
                    cpu_speed_21000855272=; cpu_core_count_21000855272=; mac_address_21000855272=; uuid_21000855272=; hostname_21000855272=; computer_ip_address_21000855272=; last_login_by_21000855272=; dp_location_21000855272=; secret_squirrel_21000855272=This is a test of the secret squirrel network; depreciation_id=; salvage=}
name              : Laptop9999
asset_type_id     : 21000855304
asset_tag         : 9999
impact            : low
description       : Apple Laptop
end_of_life       : 
discovery_enabled : True
usage_type        : permanent
created_at        : 6/23/2023 5:15:05 PM
updated_at        : 1/2/2024 4:34:05 PM
location_id       : 
department_id     : 
agent_id          : 
user_id           : 
group_id          : 
assigned_on       : 
workspace_id      : 3
author_type       : User
id                : 21001910978
display_id        : 3674

Keep in mind, another gotcha is that to retrieve type fieldsof an Asset object, it costs additional API calls (see Note 4 here: Service Desk API for Developers | Freshservice. Unfortunately, we cannot change the base Asset object, so you have to create custom fields in the layers and pay penance for getting the data.

2 Likes

Hi @rasimm

Thx for the reply.
Do follow you with how to get the type_fields.

Here, from my postman I have got the asset with the include (more expensive api rate) of type fields. The field is “secret_p_22000162827”

However, when updating the field I get a 400 error as the API doesn´t allow it:

Hence we are not able to update the fields (e.g. a password a printer, lock combination for a facility) for the secret group. So we are not able to continue with this project.

The payload is missing type_fields, it should be:

"type_fields": {
    "secret_p_22000162827": "UPDATE THIS FIELD"
  }
2 Likes