resources/customproperty.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function Get-QlikCustomProperty {
    [CmdletBinding()]
    param (
        [parameter(Position = 0)]
        [string]$id,
        [string]$filter,
        [switch]$full,
        [switch]$raw
    )

    PROCESS {
        $path = "/qrs/custompropertydefinition"
        If ( $id ) { $path += "/$id" }
        If ( $full ) { $path += "/full" }
        If ( $raw ) { $rawOutput = $true }
        return Invoke-QlikGet $path $filter
    }
}

function New-QlikCustomProperty {
    [CmdletBinding()]
    param (
        [string]$name,
        [string]$valueType = "Text",
        [string[]]$choiceValues,

        [ValidateSet("App", "ContentLibrary", "DataConnection", "EngineService", "Extension", "ProxyService", "ReloadTask", "RepositoryService", "SchedulerService", "ServerNodeConfiguration", "Stream", "User", "UserSyncTask", "VirtualProxyConfig", IgnoreCase = $false)]
        [string[]]$objectTypes
    )

    PROCESS {
        $json = @{
            name = $name;
            valueType = $valueType;
            objectTypes = $objectTypes
        }
        if ($ChoiceValues) { $json.Add("ChoiceValues", $ChoiceValues) }
        $json = $json | ConvertTo-Json -Compress -Depth 10

        return Invoke-QlikPost "/qrs/custompropertydefinition" $json
    }
}

function Remove-QlikCustomProperty {
    [CmdletBinding()]
    param (
        [parameter(Position = 0, ValueFromPipelinebyPropertyName = $true)]
        [string]$id
    )

    PROCESS {
        return Invoke-QlikDelete "/qrs/custompropertydefinition/$id"
    }
}

function Update-QlikCustomProperty {
    [CmdletBinding()]
    param (
        [parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelinebyPropertyName = $True, Position = 0)]
        [string]$id,
        [string]$name,
        [string]$valueType = "Text",
        [string[]]$choiceValues,

        [ValidateSet("App", "ContentLibrary", "DataConnection", "EngineService", "Extension", "ProxyService", "ReloadTask", "RepositoryService", "SchedulerService", "ServerNodeConfiguration", "Stream", "User", "UserSyncTask", "VirtualProxyConfig", IgnoreCase = $false)]
        [string[]]$objectTypes
    )

    PROCESS {
        $prop = Get-QlikCustomProperty $id -raw
        if ( $name ) { $prop.name = $name }
        if ( $valueType ) { $prop.valueType = $valueType }
        if ( $choiceValues -is [array]) { $prop.choiceValues = $choiceValues }
        if ( $objectTypes ) { $prop.objectTypes = $objectTypes }
        $json = $prop | ConvertTo-Json -Compress -Depth 10
        return Invoke-QlikPut "/qrs/custompropertydefinition/$id" $json
    }
}