Auto - Populate survey answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 08:30 AM
Hello I have been trying to see if its possible to auto-populate a survey questions value when the survey is inserted so when the user opens the survey a question is already filled out, Does anyone know if this is possible? I have been trying using what should be a pretty simple business rule script but it isnt working here is the script
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.log('This script hit');
gs.log('Query conditions: instance=' + current.getUniqueValue());
var survey_question_response_GR = new GlideRecord('asmt_assessment_instance_question');
survey_question_response_GR.addQuery('instance', current.getUniqueValue());
survey_question_response_GR.addQuery('metric','6e9da4562f000110a537d3f62799b6d6');
survey_question_response_GR.query();
gs.log('querry sucessful');
gs.log('Number of records found: ' + survey_question_response_GR.getRowCount());
while (survey_question_response_GR.next()) {
survey_question_response_GR.setValue('string_value','This is a test');
survey_question_response_GR.update();
gs.log('should work');
}
})(current, previous);
When I use this script the logs are returning no results which is odd, when I remove the filtering of "instance" it does show all the values correctly but even then it doesnt update them as intended, with that line the row count returns 0 even though the log at the top does show the survey record.
Any help would be appreciated, also curious if its even possible.