Use a power survey to get and post profile variables in Community. These scripts will only work with live responses; test responses
will not return or write profile variables.
Note: If you rename profile variables after the power survey is live, it
will break the get and post functionality. You must update the scripts with the
new profile variable names.
Get a member's profile variable value
Example: Use a profile variable to show or hide a
question
Your power survey contains the following single choice profile
question:
Country
Canada
United States
Mexico
However, you only want to show the question to members who do not
already have a profile variable value for
"Country_PV" in the Community database. To do this, you
would create a script to retrieve the member value for
"Country_PV" in the Community database:
ChoiceQuestion Sparq1Single = Country;
String Sparq3PVName = "Country_PV";
string Sparq3PVValue = GetProfileVariableText(Sparq3PVName);
foreach(Answer ans in Sparq1Single.Answers) {
if (ans.Text == Sparq3PVValue) {
ans.Selected = true;
break;
}
}
Save(Sparq1Single);
Then you create a condition to hide the question in your Power
Survey when there is already a value for
"Country". After you distribute your power survey, only the
members who do not have a profile variable value for "Country_PV" will see the
question.
Note: Place your GET script before the profile question you want to show
or hide in your power survey.
Profile Variable Type
Script template
Notes
Single Choice
ChoiceQuestion Sparq1Single = Single_Choice_Get;
String Sparq3PVName = "GetSingleChoicePV";
string Sparq3PVValue = GetProfileVariableText(Sparq3PVName);
foreach(Answer ans in Sparq1Single.Answers) {
if (ans.Text == Sparq3PVValue) {
ans.Selected = true;
break;
}
}
Save(Sparq1Single);
Single_Choice_Get
is the name of the Single Choice question in your power survey.
GetSingleChoicePV
is the name of the Single Choice profile variable as it appears in Community.
Date_Get
is the name of the Date question in your power survey.
Sparq3PVName
is the name of the Date profile variable as it appears in Community.
Set a profile variable in a survey
Add the following scripts to translate answer options in single and
multiple choice questions to the default language. You can use the script
On Exit in the profile question, or in a
separate Script action after the profile question.
Note:For multilingual power surveys:
The Community
profile variable must be in the Community's default language.
The survey must be
authored in the default language regardless of whether you distribute the
survey in that language.
Profile variable data
will appear in the default language in your reports.
The answer options in
your power survey must match the options in your profile variable exactly.
Replace
Age_RollUp_v2 with
the name of the Single Choice Recode question
in your power
survey.
Replace
PQ_AgeRollUp with
the name of the Single Choice
Recode profile
variable as it appears in Community.
Multiple Choice Recode
DynamicChoiceQuestion Sparq1Multi = Kids_Age_RollUp;
String Sparq3PVName = "PQ_AgeRollUp_KidsAtHome";
ArrayList selAnswers = new ArrayList();
foreach(DynamicAnswer ans in Sparq1Multi.GetSelectedAnswers())
selAnswers.Add(ans.Text1);
SetProfileVariableText(Sparq3PVName,
(string[])selAnswers.ToArray(typeof(string)));
Replace
Kids_Age_RollUp
with the name of the Multiple Choice Recode question in your power survey.
PQ_AgeRollUp_KidsAtHome
is the name of the Multiple Choice
Recode profile
variable as it appears in Community.
When using a question to set the profile variable, paste the script
into the
On Exit tab of the script editor. The script
must appear after the point in the survey where the recode conditions are met.
If you are unsure of where to place the script, you can add a script
action to the end of your survey before the termination point.