Question T22544
Visible to All Users

survey.setValue and survey.mergeData

created 4 days ago (modified 4 days ago)

Hi,

How setValue and mergeData operations differ from each other? Which one is more efficient? Can we consider using mergeData for setting multiple values at once in Survey?

TypeScript
survey.setValue('firstname', 'John'); survey.setValue('lastname', 'Smith');
TypeScript
survey.mergeData({'firstname': 'John', 'lastname': 'Smith'});

Answers approved by surveyjs Support

created 4 days ago

Hello Nitish,
The SurveyModel.setValue function assigns a new value to a given question. A default question value is overwritten by the SurveyModel.setValue function. The SurveyModel.mergeData function loads a specified response object to a survey and preserves default values for other questions which were not directly included into a response object. For instance, if your form contains other fields except first and last name, and those fields contain default values, those default values will persist. For more information on how to load single and multiple question values, please refer to our documentation: Populate Form Fields.

Let me know if you have further questions.