Question T2040
Visible to All Users

Validating the Survey Result via Expressions in code (angular)

created 6 years ago

Hi,
Is there any way to validate my Survey Result via expressions which are used for "visible if" and "Enable If" ?
for example a have the following result:

{
"question1": "item1",
"question2": "answer1",
"question3": "answer2"
}

here is the expression:
{question1} = "item1" and {question2} = 'answer1'

my expectation:

bool Check(SurevayResult,expression)
{
//in this case the result should be true
}

Best regards
Amin

Answers approved by surveyjs Support

created 6 years ago

Hello,
The latest version of survey library has the following functions:

JavaScript
survey.runExpression(expression: string): any; survey.runCondition(condition: string): boolean;

It uses data in survey.

Thank you,
Andrew
SurveyJS Team

    Other Answers

    created 6 years ago

    I found this and it works for this version "v1.0.65"

    var conditionRunner = new Survey.ConditionRunner(expression7);
    var values = survey.getFilteredValues();
    var properties = survey.getFilteredProperties();
    var result = conditionRunner.run(values, properties);

    can I trust it or is there any bug here?

      Comments (1)

        That is the correct code. However, I would recommend to migrate to the latest version.

        Thank you,
        Andrew
        SurveyJS Team

        created 6 years ago

        Hello ,

        the version of library is "v1.0.65" and I can not find runExpression or runCondition method for the survey:

        var survey = new Survey.Model(JSON.parse(surveyJSON));
        survey.(does not contain runExpression or runCondition).

        Could you please help me more.

        Regards

          Comments (1)

            You may upgrade to v1.0.85.

            Thank you,
            Andrew
            SurveyJS Team