Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Portal page, retrieving question text, words definitions in Server Side javascript not working

JeraldP
Tera Contributor

// Portal page, retrieving question text from a table (server side) and changing the innerHTML to display the definition // when a user hovers over the word in the question text. 

// Currently the query to a table for the questions to be returned.

var surveyQuestions = new GlideRecord( table question_instance);

surveyQuestions.addQuery("u_survey.u_year", data.currentYear);

surveyQuestions.addQuery("u_questiony.u_ecs_question_id", options.question_id);

surveyQuestions.Query();

surveyQuestions.next();

 

data.question = { };

data.question.id = surveyQuestions.getValue('sys_id");

data.question.question = surveyQuestions.getElement("u_question.u_question").getDisplayValue();

//once you have the question text call function replaceWordsWithDefinitions(data.question.id, data.question.question);

 

 

// retrieving words and their definitions from a table (server side) and changing the innerHTML to display the  //definition when a user hovers over the word in the question text. 

// Pass the question id and the quetion text to  the function..

 

function  replaceWordsWithDefinitions(id, textQuestion) {

var wordDefinitions = [];

var gr = new GlideRecord( table with Words and corresponding Definitions);

gr.Query();

while(gr.next())  {

        wordDefinitions.push( {

        word: gr.getValue('word');

        definition: gr.getValue('definition');

        });

    }

wordDefinitions.forEach(function(wordDefinition)  {

       var regex = new RegExp('\\b' +  wordDefinition.word  + '\\b', 'gi');

       textQuestion.innerHTML = textQuestion.innerHTML.replace(regex, '<span title=" '  +  wordDefinition.definition +  ' ">'  + wordDefinition.word + '</span>');

  });

}

0 REPLIES 0