/
fnc_New-HB-Form-Questions.ps1
85 lines (76 loc) · 2.04 KB
/
fnc_New-HB-Form-Questions.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
80
81
82
83
84
85
function New-HB-Form-Question
{
param (
[string]$form_id,
[string]$question,
[string]$question_id,
[string]$answer,
[string]$answer_value,
# Provide a list of field types
[Parameter (
Mandatory = $true,
ParameterSetName = 'field_type'
)]
[ValidateSet ('text', 'date', 'textarea')]
[string]$field_type,
[string]$entity_type = "request"
)
$newObject = @{
form_id = $form_id
question = $question
question_id = $question_id
answer = $answer
answer_value = $answer_value
field_type = $field_type
entity_type = $entity_type
hbfield = @{
question = $question
field = @{
id = $question_id
defLabel = $question
transLabel = 'x'
binding = "global.$form_id.$question_id"
noInvisibleValue = $false
design = @{
isVisible = $true
isMandatory = $false
isReadOnly = $false
showIfEmpty = $false
extraClass = ' '
}
control = @{
type = $field_type
}
uid = ''
}
value = $answer_value
}
}
return $newObject
}
<# Example usage
# Define empty array
$questions = @()
# Add question to array. Run as many times as necessary
$questions += New-HB-Form-Question `
-form_id 'form_1' `
-question 'Who is the leaver?' `
-question_id 'h_custom_h' `
-answer "$leaver_user_name" `
-answer_value "$leaver_user_username" `
-field_type 'text' `
-entity_type 'request'
# When ready to run the API to log a ticket, include the questions converted to JSON
# (Below is a custom function to make it easy to run the logServiceRequest API)
$leavers_raise_request = New-HB-ServiceRequest `
-instanceName $hornbill_instanceName `
-instanceZone $hornbill_instanceZone `
-instanceKey $hornbill_APIKey `
-summary $leavers_summary `
-serviceName "Leavers" `
-catalogName "Log a Leaver request" `
-sourceType "Business World On" `
-teamId "HornbillTesting" `
-priorityName "Priority 4" `
-questions ($questions | ConvertTo-Json -Compress)
#>