';
}
else{
innerhtml2 += '
';
}
}
// Inject parent markup
$(ParentDiv).find(".form-child-panel:last-child").append(innerhtml2);
// Add picklist values
var picklistHtml2 = '';
// console.log("possibleResponses : " + val3.possibleResponses);
$.each(val3.possibleResponses, function(k, val4) {
picklistHtml2 += '
';
});
var escapedKey = "parentPkListAns" + val3.id + newKey;
escapedKey = escapedKey.replace(/(:|\.|\[|\]|,|=|@)/g, "\\$1");
var SelectBox = $('.injectQuestions').find("." + escapedKey);
for(i = 0; i < SelectBox.length; i++) {
if($(SelectBox[i]) !== undefined) {
$(SelectBox[i]).append(picklistHtml2);
}
}
//$(document.getElementById("parentPkListAns" + val3.id + newKey)).append(picklistHtml2);
// Re-initialize markup variable
innerhtml2 = '';
});
$(ParentDiv).find(".form-child-panel:last-child").append('
');
$(ParentDiv).find(".form-child-panel:last-child").append('
');
}
innerhtml = '';
}
});
});
//Added by Shiva to Dynamically remove or Delete Groups
//When it removes groups, it also deletes answers corresponding to deleted group if any
$(".injectQuestions").off("click", ".glyphicon-trash").on("click", ".glyphicon-trash", function(e) {
//get the parent question to which the group to be deleted belongs to
var parentObject = parseInt($(this).attr("id").split("-")[1]);
var totalLen = Object.keys(questionsList[parentObject].Map_Of_AnswerGroup_childQuestionsGroup).length;
if(totalLen > 1){
//gets the specific group that needs to be deleted
var ToBeDeletedGroup = $(this).attr("id").split("-")[2] + '-' + (parseInt($(this).attr("id").split("-")[3]).toString());
//array to store the answers that needs to be deleted when group is deleted
var recordsAnsIds = [];
$.each(questionsList[parentObject].Map_Of_AnswerGroup_childQuestionsGroup[ToBeDeletedGroup], function(k, val3) {
//populting the existing answers of the group which need to be deleted
if(val3.answerId != '') {
recordsAnsIds.push(val3.answerId);
}
});
//below line deletes the element from the map
delete questionsList[parentObject].Map_Of_AnswerGroup_childQuestionsGroup[ToBeDeletedGroup];
//below line removes the mark up from the dom
var escapedGrpName = ToBeDeletedGroup.replace(/(:|\.|\[|\]|,|=|@)/g, "\\$1");
$(".injectQuestions").find("."+escapedGrpName).remove();
//below logic deletes the answers of the group which needs to be deletes
if(recordsAnsIds.length > 0) {
var result = sforce.connection.deleteIds(recordsAnsIds);
// If insert succeeds
if(result[0].success == 'true') {
reloadAttachments();
reloadQuestions();
}
}
}else{
OH_MODAL_UTILITY.errorMessageModal('At least one set of responses must be provided.');
}
});
console.log('Exit loadDynEvents Function');
},
/* Load all events */
loadEvents: function() {
// Event to capture parent question's answer
console.log('Inside Load Events Function');
$("#saveQuestionsSection").on("click", function() {
OH_NOTIFICATIONS.spinnerStart();
//var isDateValid = SRQUESTIONSCOMPNS.validateDates();
SRQUESTIONSCOMPNS.saveRecords();
console.log("After SaveRecords"+ isValid);
var isValid = SRQUESTIONSCOMPNS.validateQuestions();
var isoverlap = false;
var iserror = false;
var srid = licGlobalObj.currentRecId;
var srdate = sforce.connection.query("SELECT Supervision_Beginning_Date__c,Supervision_End_Date__c,hasOverLap__c, MUSW__Type__c,Work_Hours__c,Total_Supv_Hours__c from MUSW__Application2__c where id ='"+srid+"' limit 1");
records = srdate.getArray("records");
var startdate = records[0].Supervision_Beginning_Date__c;
var enddate = records[0].Supervision_End_Date__c;
var srtype = records[0].MUSW__Type__c;
var overlap=records[0].hasOverLap__c;
var workHours = Math.floor(records[0].Work_Hours__c*100);
var totalSupvHours = Math.floor(records[0].Total_Supv_Hours__c*100);
console.log ('overlap '+overlap);
console.log ('overlap type '+ typeof overlap);
console.log ('srtype '+ srtype);
var datecheck = new Date();
var currentdate = datecheck.getFullYear()+'-'+('0'+datecheck.getMonth()).slice(-2)+'-'+('0'+datecheck.getDate()).slice(-2);
var startCheck = new Date(startdate);
var startDateCheck = startCheck.getFullYear()+'-'+('0'+startCheck.getMonth()).slice(-2)+'-'+('0'+startCheck.getDate()).slice(-2);
var endCheck = new Date(enddate);
var endDateCheck = endCheck.getFullYear()+'-'+('0'+endCheck.getMonth()).slice(-2)+'-'+('0'+endCheck.getDate()).slice(-2);
var validatestartDate = startDateCheck > currentdate ? true : false;
var validateendDate = endDateCheck > currentdate ? true : false;
var validatestartendequalDate = startdate == enddate ? true : false;
var validatestartdategreaterthanendDate = startdate > enddate ? true : false;
var validateHours = workHours > totalSupvHours ? false : true;
if((srtype == 'Supervision Report' || srtype == 'Log Training Hours') && (validatestartDate === true || validateendDate === true || validatestartendequalDate === true || validatestartdategreaterthanendDate || validateHours )){
iserror = true;
}
else
{
iserror = false;
}
if(isValid) {
if((iserror===false)){
if(srtype == 'Restore Escrow')
window.location.href = '/OH_COSRestoreEscrowQuestions?licenseId=' + licid.currentRecId+'&showupload=true&requestid='+licGlobalObj.currentRecId;
else
window.location.href = srlink + licid.currentRecId+'&showupload=true&requestid='+licGlobalObj.currentRecId;
console.log('Hello'+vwindow.location.href);
}
else
{
if(validatestartDate === true)
{
OH_MODAL_UTILITY.errorMessageModal('Please check the supervision start date can not be future date');
OH_NOTIFICATIONS.spinnerStop();
}
if(validateendDate === true)
{
OH_MODAL_UTILITY.errorMessageModal('Please check the supervision end date can not be future date');
OH_NOTIFICATIONS.spinnerStop();
}
if(validatestartendequalDate === true)
{
OH_MODAL_UTILITY.errorMessageModal('Please check the supervision start date and end date can not have same dates');
OH_NOTIFICATIONS.spinnerStop();
}
if(validatestartdategreaterthanendDate === true)
{
OH_MODAL_UTILITY.errorMessageModal('Please check the supervision start date can not be greater than end date');
OH_NOTIFICATIONS.spinnerStop();
}
if(validateHours === true)
{
OH_MODAL_UTILITY.errorMessageModal('Please check the work hours should always be greater than the supervison hours');
OH_NOTIFICATIONS.spinnerStop();
}
}
}
/*if(isValid){
window.location.href = srlink + licid.currentRecId+'&showupload=true&requestid='+licGlobalObj.currentRecId;
}*/
});
$("#saveAndFinishLaterBtn").on("click", function(){
OH_NOTIFICATIONS.spinnerStart();
SRQUESTIONSCOMPNS.saveRecords();
OH_NOTIFICATIONS.spinnerStop();
OH_MODAL_UTILITY.openCancelConfirmationModal('Are you sure you want to save and come back later?', 'Confirm Exit',null, goToDashboard);
});
console.log('Exit Load Events Function');
},
/* Show or hide child questions */
showHideChildQuestions: function(parentQueObj, currentAns, currentObjId) {
console.log('Inside Show Child Question Function');
var hasChildQuestions = false;
var GroupQuestions = false;
if(parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup_JSON != null) {
GroupQuestions = true;
}
$.each(parentQueObj.childQueList, function(j, val2) {
if(val2.qualifyingParentResponse == currentAns) {
hasChildQuestions = true;
}
if(parentQueObj.id == currentObjId) {
if(val2.qualifyingParentResponse == currentAns) {
$(".childQue" + val2.id).show();
}
else {
$(".childQue" + val2.id).hide();
$("#radioY" + val2.id).prop("checked", false);
$("#radioN" + val2.id).prop("checked", false);
$("#parentPkListAns" + val2.id).val('');
$("#textAns" + val2.id).val('');
}
}
else if(val2.id == currentObjId) {
if(val2.qualifyingResponseForComment == currentAns) {
$(".parentQueComment" + val2.id).show();
}
else {
$(".parentQueComment" + val2.id).hide();
}
}
});
if(hasChildQuestions && parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup_JSON == null) {
$(".parentQue" + parentQueObj.id).show();
}
else {
$(".parentQue" + parentQueObj.id).hide();
$.each(parentQueObj.childQueList, function(j, val2) {
try {
$("#radioY" + val2.id).prop("checked", false);
$("#radioN" + val2.id).prop("checked", false);
$("#parentPkListAns" + val2.id).val('');
$("#textAns" + val2.id).val('');
$("#parentQueComment" + val2.id).val('');
$(".parentQueComment" + val2.id).hide();
}
catch(e) {
console.log(e);
}
});
}
//Loop through Child Group Questions added by Shiva to handle Group Visibility based onn response to parents
if(parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup_JSON != null) {
// console.log('Entering the-----'+parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup);
Object.keys(parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup).map(function(key, index) {
$.each(parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup[key], function(k, val3) {
if(val3.qualifyingParentResponse == currentAns) {
hasChildQuestions = true;
}
if(parentQueObj.id == currentObjId) {
if(val3.qualifyingParentResponse == currentAns) {
// console.log('answers match ' + key);
// console.log('html element------'+ $(".childQue" + val3.id).html());
$(".childQue" + val3.id).show();
}
else {
$(".childQue" + val3.id).hide();
$(document.getElementById("radioY" + val3.id + key)).prop("checked", false);
$(document.getElementById("radioN" + val3.id + key)).prop("checked", false);
$(document.getElementById("parentPkListAns" + val3.id + key)).val('');
$(document.getElementById("textAns" + val3.id + key)).val('');
}
}
else if(val3.id == currentObjId) {
if(val3.qualifyingResponseForComment == currentAns) {
$(".parentQueComment" + val3.id).hide();
}
else {
$(".parentQueComment" + val3.id).hide();
}
}
});
if(hasChildQuestions) {
var escapedKey = key.replace(/(:|\.|\[|\]|,|=|@)/g, "\\$1");
$("." + escapedKey).show();
}
else {
var escapedKey = key.replace(/(:|\.|\[|\]|,|=|@)/g, "\\$1");
$("." + escapedKey).hide();
$.each(parentQueObj.Map_Of_AnswerGroup_childQuestionsGroup[key], function(k, val3) {
try {
$(document.getElementById("radioY" + val3.id + key)).prop("checked", false);
$(document.getElementById("radioN" + val3.id + key)).prop("checked", false);
$(document.getElementById("parentPkListAns" + val3.id + key)).val('');
$(document.getElementById("textAns" + val3.id + key)).val('');
$(document.getElementById("parentQueComment" + val3.id + key)).val('');
$(".parentQueComment" + val3.id).hide();
}
catch(e) {
console.log(e);
}
});
}
});
}
console.log('Exit Show Child Question Function');
},
deleteRecords: function() {
console.log('Inside delete Record Function');
var questionIdList = '';
var recordsAnswers = [];
var recordsAnsIds = [];
if(questionsList.length > 0) {
var isFirstObj = true;
$.each(questionsList, function(i, val) {
if(isFirstObj) {
questionIdList += "Question__c = '" + val.id + "'";
isFirstObj = false;
}
else {
questionIdList += " OR Question__c = '" + val.id + "'";
}
$.each(val.childQueList, function(j, val2) {
questionIdList += " OR Question__c = '" + val2.id + "'";
});
//Loop through Child Group Questions
if(val.Map_Of_AnswerGroup_childQuestionsGroup_JSON != null) {
Object.keys(val.Map_Of_AnswerGroup_childQuestionsGroup).map(function(key, index) {
$.each(val.Map_Of_AnswerGroup_childQuestionsGroup[key], function(k, val3) {
questionIdList += " OR Question__c = '" + val3.id + "'";
});
});
}
});
// Build query string
var queryAnswers = '';
queryAnswers = "SELECT Id, Name, Answer_Text__c, Question__c From Answer__c WHERE " + lookupFieldName + " = '" + licGlobalObj.currentRecId + "' AND (" + questionIdList + ")";
// Execute query and get records
var resultAnswers = sforce.connection.query(queryAnswers);
recordsAnswers = resultAnswers.getArray("records");
$.each(recordsAnswers, function(i, val) {
recordsAnsIds.push(val.Id);
});
$.each(questionsList, function(i, val) {
val.answerText = '';
$("#radioY" + val.id).attr(':checked', false);
$("#radioN" + val.id).attr(':checked', false);
$.each(val.childQueList, function(j, val2) {
val2.answerText = '';
$("#radioY" + val2.id).attr(':checked', false);
$("#radioN" + val2.id).attr(':checked', false);
});
});
}
// Delete - REST call
var result = sforce.connection.deleteIds(recordsAnsIds);
console.log('Exit Delete Record Function');
},
/****** Delete Expired Question Answers **************/
/***
For example: I have started a license application. Question-x is active when I started the application and I answered Question-x.
Tomorrow when I come back to resume my application, the question-x is no longer active which means it is expired. This answer needs to be
deleted since my application is not submitted yet. This deletes happens on save of answers.
***/
deleteExpiredAnswers: function(){
console.log('Inside deleteExpiredAnswers Function');
try{
var recordsAnsIds = [];
if(answerList_ToBeDeleted.length > 0&&answerList_ToBeDeleted.trim()!='') {
// console.log('at 674'+answerList_ToBeDeleted);
$.each(answerList_ToBeDeleted,function(i,val){
recordsAnsIds.push(val.Id);
});
}
if(recordsAnsIds.length>0)
{
var result = sforce.connection.deleteIds(recordsAnsIds);
// console.log('---> Delete Complete. Result at 459: ' + result);
}
}catch(e){console.log(e);}
console.log('Exit deleteExpiredAnswers Function');
},
/* Save answers to Answer object */
saveRecords: function() {
console.log('Inside Save Record Function');
// console.log('at 691--->'+answerList_ToBeDeleted);
// $("#saveQuestionsSection").attr("disabled", "");
// Start spinner
// Initialize list
console.log('Inside Save Records Function');
var answersList = [];
// Delete previous answers
// SRQUESTIONSCOMPNS.deleteRecords();
// Loop through parent questions
SRQUESTIONSCOMPNS.deleteExpiredAnswers();
$.each(questionsList, function(i, val) {
if(val.show) {
// Initialize object of Answer object
var ansObj = new sforce.SObject("Answer__c");
eval("ansObj." + lookupFieldName + " = licGlobalObj.currentRecId");
ansObj.Question__c = val.id;
ansObj.Answer_Text__c = '';
ansObj.Comment__c = '';
//setting submitted by portal user as true
ansObj.Submitted_By_Portal_User__c = true;
// If Yes-No type of question
if(val.dataType == 'Yes_No') {
// Answer - Yes
if($("#radioY" + val.id).is(':checked')) {
ansObj.Answer_Text__c = 'Yes';
val.answerText = 'Yes';
}
// Answer - No
else if($("#radioN" + val.id).is(':checked')) {
ansObj.Answer_Text__c = 'No';
val.answerText = 'No';
}
// Add comment
val.answerComment = $("#parentQueComment" + val.id).val();
ansObj.Comment__c = $("#parentQueComment" + val.id).val();
}
// If picklist type of question
else if(
(val.dataType == 'Picklist') && ($("#parentPkListAns" + val.id).val() != null)) {
ansObj.Answer_Text__c = $("#parentPkListAns" + val.id).val();
val.answerText = $("#parentPkListAns" + val.id).val();
} else if(
(val.dataType == 'Multi-Select Picklist') && ($("#parentPkListAns" + val.id).val() != null)) {
ansObj.Answer_Text__c = $("#parentPkListAns" + val.id).val().join(";");
val.answerText = $("#parentPkListAns" + val.id).val().join(";");
}
// If text type of question
else if(
(val.dataType == 'Text') && ($("#parentTextAns" + val.id).val() != null)) {
ansObj.Answer_Text__c = $("#parentTextAns" + val.id).val();
val.answerText = $("#parentTextAns" + val.id).val();
}
// Push object into array list
//if((ansObj.Answer_Text__c != '') && (ansObj.Answer_Text__c != null)) {
answersList.push(ansObj);
//}
// Loop through child questions
var somevariable =val;
$.each(val.childQueList, function(j, val2) {
if(val2.show&&somevariable.answerText==val2.qualifyingParentResponse) {
// Initialize object of Answer object
var ansObj = new sforce.SObject("Answer__c");
eval("ansObj." + lookupFieldName + " = licGlobalObj.currentRecId");
ansObj.Question__c = val2.id;
ansObj.Answer_Text__c = '';
ansObj.Comment__c = '';
//setting submitted by portal user as true
ansObj.Submitted_By_Portal_User__c = true;
// If Yes-No type of question
if(val2.dataType == 'Yes_No') {
// Answer - Yes
if($("#radioY" + val2.id).is(':checked')) {
ansObj.Answer_Text__c = 'Yes';
val2.answerText = 'Yes';
}
// Answer - No
else if($("#radioN" + val2.id).is(':checked')) {
ansObj.Answer_Text__c = 'No';
val2.answerText = 'No';
}
// Add comment
val2.answerComment = $("#parentQueComment" + val2.id).val();
ansObj.Comment__c = $("#parentQueComment" + val2.id).val();
}
// If picklist
else if(val2.dataType == 'Picklist' || val2.dataType == 'Multi-Select Picklist') {
ansObj.Answer_Text__c = $("#parentPkListAns" + val2.id).val();
val2.answerText = $("#parentPkListAns" + val2.id).val();
}
// If text
else if(
(val2.dataType == 'Text') && ($("#textAns" + val2.id).val() != '')) {
ansObj.Answer_Text__c = $("#textAns" + val2.id).val();
val2.answerText = $("#textAns" + val2.id).val();
}
// Push object into array list
if(
(ansObj.Answer_Text__c != '') && (ansObj.Answer_Text__c != null)) {
answersList.push(ansObj);
}
}
});
// console.log(val.Map_Of_AnswerGroup_childQuestionsGroup_JSON);
//Loop through Child Group Questions to save Group Question Answers
if(val.Map_Of_AnswerGroup_childQuestionsGroup_JSON != null) {
var somevariable =val;
Object.keys(val.Map_Of_AnswerGroup_childQuestionsGroup).map(function(key, index) {
$.each(val.Map_Of_AnswerGroup_childQuestionsGroup[key], function(k, val3) {
if(val3.show&&somevariable.answerText==val3.qualifyingParentResponse) {
// Initialize object of Answer object
var ansObj = new sforce.SObject("Answer__c");
eval("ansObj." + lookupFieldName + " = licGlobalObj.currentRecId");
ansObj.Question__c = val3.id;
ansObj.Answer_Text__c = '';
ansObj.Comment__c = '';
ansObj.Answer_Group__c = key;
//setting submitted by portal user as true
ansObj.Submitted_By_Portal_User__c = true;
// If Yes-No type of question
if(val3.dataType == 'Yes_No') {
// Answer - Yes
var Elementname = document.getElementsByName("radio" + val3.id + key);
for(i = 0; i < Elementname.length; i++) {
if(Elementname[i].checked) {
if($(Elementname[i]).hasClass('yes')) {
// console.log('Selected Answer is Yes');
ansObj.Answer_Text__c = 'Yes';
val3.answerText = 'Yes';
}
else if($(Elementname[i]).hasClass('no')) {
// console.log('Selected Answer is No');
ansObj.Answer_Text__c = 'No';
val3.answerText = 'No';
}
}
}
// Add comment
val3.answerComment = $(document.getElementById("parentQueComment" + val3.id + key)).val();
ansObj.Comment__c = $(document.getElementById("parentQueComment" + val3.id + key)).val();
}
// If picklist
else if(val3.dataType == 'Picklist' || val3.dataType == 'Multi-Select Picklist') {
var escapedKey = 'parentPkListAns' + val3.id + key;
escapedKey = escapedKey.replace(/(:|\.|\[|\]|,|=|@)/g, "\\$1");
var SelectBox = $('.injectQuestions').find('.' + escapedKey);
for(i = 0; i < SelectBox.length; i++) {
if($(SelectBox[i]).val() != '') {
//console.log('at 814 '+$(SelectBox[i]).val());
ansObj.Answer_Text__c = $(SelectBox[i]).val();
val3.answerText = $(SelectBox[i]).val();
}
}
}
// If text
else if((val3.dataType == 'Text')) {
var escapedKey = 'textAns' + val3.id + key;
escapedKey = escapedKey.replace(/(:|\.|\[|\]|,|=|@)/g, "\\$1");
var TextInputs = $('.injectQuestions').find('.' + escapedKey);
for(i = 0; i < TextInputs.length; i++) {
//console.log("val3-" + $(TextInputs[i]).val());
if($(TextInputs[i]).val() != '') {
//console.log('at 826 '+$(TextInputs[i]).val());
ansObj.Answer_Text__c = $(TextInputs[i]).val();
val3.answerText = $(TextInputs[i]).val();
}
}
}
// Push object into array list
//if((ansObj.Answer_Text__c != '') && (ansObj.Answer_Text__c != null)) {
//('ansObj at 837 '+ansObj);
answersList.push(ansObj);
//}
}
});
});
}
}
});
var questionIdList = '';
var isFirstObj = true;
// let set = new Set();
var uniquequestions = new Map();
$.each(questionsList, function(i, val) {
if(isFirstObj) {
questionIdList += "Question__c = '" + val.id + "'";
uniquequestions.set(val.id);
isFirstObj = false;
}
else {
questionIdList += " OR Question__c = '" + val.id + "'";
uniquequestions.set(val.id);
}
$.each(val.childQueList, function(j, val2) {
questionIdList += " OR Question__c = '" + val2.id + "'";
uniquequestions.set(val2.id);
});
//Loop through Child Group Questions
if(val.Map_Of_AnswerGroup_childQuestionsGroup_JSON != null) {
Object.keys(val.Map_Of_AnswerGroup_childQuestionsGroup).map(function(key, index) {
$.each(val.Map_Of_AnswerGroup_childQuestionsGroup[key], function(k, val3) {
questionIdList += " OR Question__c = '" + val3.id + "'";
uniquequestions.set(val3.id);
});
});
}
});
// Insert list
var questionsissue='';
uniquequestions.forEach(function(value, key, map) {
questionsissue+="'"+key+"',";
});
if(questionsissue.length>0)
{
questionsissue= questionsissue.substring(0,questionsissue.lastIndexOf(","));
}
var queryAnswers = '';
//QuestionGroup__c
queryAnswers = "SELECT Id,Comment__c, Name, Answer_Text__c,QuestionGroup__c,Answer_group__c,Question__r.Parent_Question__c, Question__c From Answer__c WHERE " + lookupFieldName + " = '" + licGlobalObj.currentRecId + "' AND Question__c IN (" + questionsissue + ")";
console.log(queryAnswers);
// Execute query and get records
var resultAnswers = sforce.connection.query(queryAnswers);
recordsAnswers = resultAnswers.getArray("records");
var prevlistanswered = new Map();
$.each(recordsAnswers, function(i, val) {
if(val.Answer_Group__c!=''&&val.Answer_Group__c!=null&&val.Answer_Group__c!=undefined){
var two = val.Question__c+val.Answer_Group__c;
prevlistanswered.set(two,val);
}else{
prevlistanswered.set(val.Question__c,val);
}
});
var currentanswers=[];
var changeddanswers=[];
if(answersList.length > 0) {
// Set Ids
// Check if the license has previous answers or they are new answers
// This section works on the principle of finding the items that currently differ from the ones the user has already saved in the backend
// if the user changes an answers , the script would find the changed answers ,delete the old answer and insert the new answers
// If the user deletes an answer to a group question, the script would also delete all answers to the child questions of the parent questio
if(prevlistanswered.size > 0) {
$.each(answersList, function(i, val) {
var val2='';
if(val.Answer_Group__c!=''&&val.Answer_Group__c!=null&&val.Answer_Group__c!=undefined){
var three = val.Question__c+val.Answer_Group__c;
val2= prevlistanswered.get(three);
}else{
val2= prevlistanswered.get(val.Question__c);
}
if( val2!=undefined){
if( val.Answer_Text__c== val2.Answer_Text__c) {
if(val.Comment__c!=''&&val.Comment__c!=null&&val2.Comment__c!=val.Comment__c)
{
val.Id= val2.Id;
currentanswers.push(val);
}
else{
val.Id = val2.Id;
}
}
else if ( val.Answer_Text__c!= val2.Answer_Text__c) {
if( val2.Comment__c!=''&&val2.Comment__c!=null)
{
val.Comment__c='';
}
if(val.Answer_Group__c==undefined)
{
currentanswers.push(val);
changeddanswers.push(val2.Id);
for (var key in prevlistanswered.map) {
if(prevlistanswered.get(key).Answer_Group__c!=null&&prevlistanswered.get(key).Answer_Group__c!=undefined){
if (prevlistanswered.get(key).Answer_Group__c.includes(val2.QuestionGroup__c)) {
changeddanswers.push(prevlistanswered.get(key).Id);
}
}
else if(prevlistanswered.get(key).Question__r.Parent_Question__c!=undefined&&prevlistanswered.get(key).Question__r.Parent_Question__c==val2.Question__c){
changeddanswers.push(prevlistanswered.get(key).Id);
}
}
}
else if((val2.Answer_Text__c!=null&&val.Answer_Text__c=='')||(val2.Answer_Text__c==null&&val.Answer_Text__c=='')||(val2.Answer_Text__c==null&&val.Answer_Text__c!='')||(val2.Answer_Text__c!=null&&val.Answer_Text__c!='')){
if( val.Answer_Text__c==''){
val.Answer_Text__c=null}
val.Id= val2.Id;
currentanswers.push(val);
}
}
}
else if( val2==undefined&&val.Answer_Text__c!=null){
currentanswers.push(val);
}
});
}
else{
$.each(answersList, function(i, val) {
currentanswers.push(val);
});
}
// Upsert
//Deleting the changed answers and updating the unchanged ones.
var maxamount=199;
var temparray=[];
var result='';
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
console.log('changeddansers ::', changeddanswers);
while(changeddanswers.length>0){
if(changeddanswers.length
0){
if(currentanswers.length