Public/Metaverse/Add-JIMMetaverseObjectTypeAttribute.ps1
|
# Copyright (c) Tetron Limited. All rights reserved. # Licensed under the Tetron Commercial License. See LICENSE file in the project root. function Add-JIMMetaverseObjectTypeAttribute { <# .SYNOPSIS Binds a custom Metaverse Attribute to a Metaverse Object Type. .DESCRIPTION Creates a binding between an existing custom Metaverse Attribute and a Metaverse Object Type, making the attribute available on objects of that type. Binding an attribute that is already bound to the Object Type is a no-op. Built-in attributes cannot be re-bound. .PARAMETER AttributeId The ID of the attribute to bind. .PARAMETER ObjectTypeId The ID of the Metaverse Object Type to bind it to. .PARAMETER ChangeReason An optional reason for the change, recorded in the attribute's Configuration Change History. .PARAMETER PassThru Returns the updated attribute. .OUTPUTS With -PassThru, the updated attribute in full; otherwise nothing. .EXAMPLE Add-JIMMetaverseObjectTypeAttribute -AttributeId 42 -ObjectTypeId 1 Binds attribute 42 to Object Type 1. .EXAMPLE Get-JIMMetaverseAttribute -Name "CostCentre" | Add-JIMMetaverseObjectTypeAttribute -ObjectTypeId 1 -PassThru Binds the CostCentre attribute (from the pipeline) to Object Type 1 and returns it. .LINK Remove-JIMMetaverseObjectTypeAttribute Get-JIMMetaverseAttribute New-JIMMetaverseAttribute #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] [OutputType('JIM.MetaverseAttributeDetailDto')] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('Id')] [int]$AttributeId, [Parameter(Mandatory)] [int]$ObjectTypeId, [Parameter()] [ValidateNotNullOrEmpty()] [string]$ChangeReason, [switch]$PassThru ) process { # Check connection first if (-not $script:JIMConnection) { Write-Error "You are not connected to JIM. Run Connect-JIM -Url <your JIM URL> to authenticate, then try again." return } if (-not $PSCmdlet.ShouldProcess("Attribute $AttributeId -> Object Type $ObjectTypeId", "Bind Metaverse Attribute to Object Type")) { return } Write-Verbose "Binding Metaverse Attribute $AttributeId to Object Type $ObjectTypeId" try { $endpoint = "/api/v1/metaverse/attributes/$AttributeId/object-types/$ObjectTypeId" if ($ChangeReason) { $endpoint += "?changeReason=$([uri]::EscapeDataString($ChangeReason))" } $result = Invoke-JIMApi -Endpoint $endpoint -Method 'POST' Write-Verbose "Bound Metaverse Attribute $AttributeId to Object Type $ObjectTypeId" if ($PassThru) { $result } } catch { Write-Error "Failed to bind Metaverse Attribute $AttributeId to Object Type ${ObjectTypeId}: $_" } } } |