-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
So, 2 things:
- I cannot ONLY update 1 item in a flexible asset, it overwrites with only the data I enter
- I have written out a way to pull the data into my $data variable, and it works for basic flexible-assets. If I add one that has a "contact" entry, it will not send back.
$org = Get-ITGlueOrganizations -filter_name "Contoso Corporation"
$alltypes = Get-ITGlueFlexibleAssetTypes
$selectedtype = $alltypes.data.attributes.name | Sort-Object | Out-GridView -Title "Select the category to search for changes" -OutputMode Single
$type = Get-ITGlueFlexibleAssetTypes -filter_name $selectedtype
$assets = Get-ITGlueFlexibleAssets -filter_flexible_asset_type_id $type.data.id -filter_organization_id $org.data.id
$chosenassets = $assets.data.attributes.name | Sort-Object | Out-GridView -Title "Select $selectedtype items to Edit" -Passthru
foreach($chosenasset in $chosenassets){
Clear-Variable data -ErrorAction SilentlyContinue
Clear-Variable asset -ErrorAction SilentlyContinue
Clear-Variable AssetTraits -ErrorAction SilentlyContinue
$asset = Get-ITGlueFlexibleAssets -filter_flexible_asset_type_id $type.data.id -filter_organization_id $org.data.id -filter_name $chosenasset
$data = @{
type = $asset.data.type
attributes = @{
traits = @{
}
}
}
[array]$AssetTraits = $asset.data.attributes.traits | Get-Member | Where-Object {$_.MemberType -eq "NoteProperty"}
for ($i = 0; $i -lt $AssetTraits.Count; $i ++)
{
if($AssetTraits[$i].Definition -match 'string' -or 'int' -or 'bool'){
$data.attributes.traits += @{
"$($AssetTraits[$i].Name)" = $asset.data.attributes.traits."$($AssetTraits[$i].Name)"
}
}
else{
[array]$NonStringObject = $asset.data.attributes.traits.'$($AssetTraits[$i].Name)'.values | Get-Member | Where-Object {$_.MemberType -eq "NoteProperty"}
for ($j = 0; $j -lt $NonStringObject.Count; $j ++){
$data.attributes.traits += @{
"$($AssetTraits[$i].Name)" = @{
"$($NonStringObject[$j].Name)" = $asset.data.attributes.traits."$($AssetTraits[$i].Name)"."$($NonStringObject[$j].Name)"
}
}
}
}
}
$changes = $data.attributes.traits | Sort-Object | Out-GridView -Title "Select Items to change on $($asset.data.attributes.name)" -Passthru
foreach($change in $changes){
Clear-Variable newvalue -ErrorAction SilentlyContinue
$newvalue = Read-Host "Enter new value for $($change.name), the current value is $($Change.value)"
if($newvalue){
$data.attributes.traits."$($Change.Name)" = $newvalue
Write-Host "Value has been changed to $($Data.attributes.traits."$($Change.Name)")"
}
else
{
Write-Host "No changes made"
}
}
Try{
Set-ITGlueFlexibleAssets -id $asset.data.id -Data $data -ErrorAction Stop
Write-Host "Updated ITG with changes"
}
Catch {
Write-Host "ITG Update Failed"
}
}
Basically, it reads everything in to the $data variable, and if it's an object type that Powershell doesn't know, it adds it in. I can compare my "asset" to my "data" and everything is exactly the same in terms of object type, membership, etc. Any insight would be appreciated.
Using a Flexible-Asset without the "contact" field, it works without issue:

Metadata
Metadata
Assignees
Labels
No labels


