Javascript Piping
Using javascript piping its possible to pipe a value that will be generated using any javascript of your choice.
A special NGSJS function can be setup to return an output of your javascript code, the output can then be stored in a Default value to show it and store it within a field
The output will only be evaluate during submit mode, if you survey answers have been submitted and you are in change mode or resume mode the value will be original one that has been saved prior resuming or changing the answers
➕Simple Fields Sum Example
Below are the steps to add a custom JavaScript that sums two fields. You can modify the code to achieve any desired output to store. Note that if you only need to sum you may consider using the existing Numeric Field type instead Create a question with 3 fields

Once created for each field involved in the calcualtion set in its answer properties its Pipe alias, this will be used later on to look up the current value.
In the Result field, open the answer settings and in the Default text value use the NGSJS function to get the value of the 2 other fields and output the result

👨💻️ pipeContext
the pipeContext is a built in object that gives you following options : Properties :
questions: Question[]List of survey questions.answers: Answer[]List of possible answers across all questions.respondent: RespondentCurrent respondent information.panelists: Panelist[]Associated panelists (if applicable).respondentAnswers: RespondentAnswer[]Answers provided by the respondent.pipeDataAttributesValues: PipeDataAttributeValue[]Additional pipe data attributes and values.
Methods
getAnswer(id: string): string
Returns the value(s) associated with a given identifier.
Supports lookup by:
Answer ID
Question ID
Reporting alias
Pipe alias
Behavior:
If the identifier matches a text-based answer, returns its value.
If it matches a question, returns selected answers.
Multiple values are returned as a comma-separated string.
isSelectedAnswer(id: string, value: string): boolean
Checks whether a specific answer is selected.
Parameters:
id: Question or answer identifiervalue: Answer identifier or value to check
Behavior:
If
idrefers to a question → checks if the specified answer is selected.If
idrefers to an answer → compares its value directly.
Returns:
trueif the answer is selected or matchesfalseotherwise
Last updated
Was this helpful?