Public/Get-SurveyDefinitions.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
<#
    .SYNOPSIS
    Query salesforce for all survey definitions

    .DESCRIPTION
    Queries for all the surveys, questions and answers

    .INPUTS
    None. You cannot pipe objects to Get-SurveyDefinitions.

    .OUTPUTS
    A hash table containing the following keys:
        answers
        surveys
        questions

    The 'answers' key contains an array of CustomPSObjects with the following members:
        Id
        phecc__Answer__c
        phecc__Survey_Question__c

    The 'surveys' key contains an array of CustomPSObjects with the following members:
        Id
        Name

    The 'questions' key contains an array of CustomPSObjects with the following members:
        Id
        phecc__Question__c
        phecc__Survey__c

    .EXAMPLE
    PS> $surveyDefs = Get-SurveyDefinitions

    .LINK
    Set-FileConfig

    .NOTES
    Assumes config is initialized for org access.
#>

function Get-SurveyDefinitions {
    Write-Verbose "Reading Org Survey Metadata"
    @{
        surveys = (invoke-sfquery "SELECT Id,Name FROM phecc__Survey__c WHERE IsDeleted = false AND phecc__Status__c = 'Published'")
        questions = (invoke-sfquery "SELECT Id,phecc__Question__c,phecc__Survey__c FROM phecc__Survey_Question__c")
        answers = (invoke-sfquery "SELECT Id,phecc__Answer__c,phecc__Survey_Question__c FROM phecc__Survey_Answer__c")
    }
}