Professional > Data management scripting > Data Management reference > Data Management functions > ReplaceCategory
 
ReplaceCategory
Replaces oldCategory with newCategory for a loop/categorical questions (used for OnNextCase events).
Syntax
ReplaceCategory(Question, oldCategory, newCategory)
Parameters
Question
Type: object
Category question or loop question.
oldCategory
Type: string
Category item that will be replaced with newCategory.
newCategory
Type: string
The new category value that replaces oldCategory.
(return)
Type: Boolean
True when oldCategory successfully replaces newCategory, otherwise False
Notes
For each question, the oldCategory can be an iteration category, a question category for a loop question, or a category for categorical question.
There are restrictions when using this function:
When the question is a category question, oldCategory and newCategory are the defined categories.
When the question is a loop question, oldCategory can be in the iteration categories or in the defined category items for the nested question.
Example
The definitions for cat, MyLoopCatQuestion, and MyLoopLogicQuestion are as follows:
cat "What animal you like?"categorical [1..]
{
Dog "Dog",
Goldfish "Goldfish",
Panda "Panda",
Giraffe "Giraffe",
snake "snake",
dontKnow "dontKnow",
Serpent "Serpent"
};

MyLoopCatQuestion - loop
{
A "A",
B "B",
C "C",
D "D"
} fields -
(
rating categorical [1..1]
{
Dog "Dog",
Goldfish "Goldfish",
Panda "Panda",
Giraffe "Giraffe",
snake "snake",
Serpent " Serpent "
};

) expand grid;

MyLoopLogicQuestion - loop
{
Dog "Dog",
Goldfish "Goldfish",
Panda "Panda",
Giraffe "Giraffe",
snake "snake",
Serpent " Serpent "
} fields -
(
YesOrNo categorical [1..1]
{
Yes "Yes",
No "No"
};

) expand grid;
ReplaceCategory(cat, "snake", "Serpent")
The related response.value for the question cat is as follows:
Before replacement
After replacement
{dog,snake,panda}
{ dog,serpent,panda }
{giraffe,snake}
{giraffe,serpent}
{dog,goldfish}
{dog,goldfish}
ReplaceCategory(MyLoopCatQuestion, "snake", "Serpent")
The related response.value for the question MyLoopCatQuestion is as follows:
Question
Before replacement
After replacement
MyLoopCatQuestion[{A}].Rating
{dog,snake,panda}
{ dog,serpent,panda }
MyLoopCatQuestion[{B}].Rating
{giraffe,snake}
{giraffe,serpent}
MyLoopCatQuestion[{C}].Rating
{dog,goldfish}
{dog,goldfish}
MyLoopCatQuestion[{D}].Rating
{snake}
{serpent}
ReplaceCategory(MyLoopLogicQuestion, "snake", "Serpent")
After running the function, the value of all sub-questions for iteration snake are copied for iteration serpent.
See also
Data Management functions