You are viewing limited content. For full access, please sign in.

Question

Question

Combine repeated comments into one multiline comments box.

asked on September 17, 2020 Show version history

With reference to this post and Xiuhong Xiang solution, could I get some help changing his solution to match my needs?

https://answers.laserfiche.com/questions/68502/Need-java-inernal-variables-to-get-text-from-the-comments-forms#68634

I have a process where users taking care of service requests may have to report in many times during the form process and the supervisors want a report that includes the comments.  I cannot do that unless I can access one field that contains all of the comments.  Xiuhong has a solution that should work, however, I am not familiar enough with JavaScript to troubleshoot my own changes.  Could you have a look and see if you can see what is wrong?

  • q58 is the multi-line field I want all comments to populate into after every submission; variable name is "RecordedActivities";
  • q60 is a read-only date field for current date (at time of each report)
  • q61 is a read-only single-line field fir current user (at time of each report)
  • q62 is a multi-line field for comments to report activities in (at time of each report)

 

I took the JavaScript Xiuhong provided in the above mentioned link and just changed the variable names and field ID numbers, but it did not result in the expected comments copied into the "RecordedActivities" field.

$(document).ready(function () {
  var RecordedActivities = $('#q58 textarea').val();
//get previous comment
  var RecordedActivities2 = $('#q58 textarea')[0].getAttribute('default-val');
//get previous DateofAction
  var DateofAction=$('#q60 input')[0].getAttribute('default-val');
//get previous action participant
  var PersonReporting=$('#q61 input')[0].getAttribute('default-val');
//get previous action
  var ActionsNotes=$('#q62 input')[0].getAttribute('default-val');
//combine the information together
  var currentinfo=""; 
  if(PersonReporting!=null){
        currentinfo=PersonReporting+", ";
      }
  if(RecordedActivities2!=null){
        currentinfo=currentinfo+RecordedActivities2+", ";
      }
  if(DateofAction!=null){
        currentinfo=currentinfo+DateofAction+", ";
      }
  if(ActionsNotes!=null){
        currentinfo=currentinfo+ActionsNotes;
      }
//append to field that display the information
if (currentinfo!=""){
  RecordedActivities = RecordedActivities + '\n\n' + currentinfo;
  $('#q58 textarea').val(RecordedActivities);   
}
  $('#q58 textarea').attr('readonly', 'True');
});

0 0

Replies

replied on September 17, 2020 Show version history

hi Connie,

I checked attached JavaScript, the problem is in line to get previous comment

  var RecordedActivities = $('#q58 textarea').val();
//get previous comment
  var RecordedActivities2 = $('#q58 textarea')[0].getAttribute('default-val');

where RecordedActivities2 should get value of q62, which default value is comment of last submission.

  var RecordedActivities = $('#q58 textarea').val();
//get previous comment
  var RecordedActivities2 = $('#q62 textarea')[0].getAttribute('default-val');

 

Another thing I noticed is that: the fields has default value of  last user submission date/user/comment in Xiuhong's solution, while described as current date/user/comment in your solution. You may want to check the default value settings as well

0 0
replied on September 18, 2020

Thanks, Ziyan.  I was thinking the //get previous comment ... the target at that point was not the new comments but the collection comments so that it could combine the old + the new.  In Xiuhong's original JavaScript his #q there was #q2 which was also the target # to save to, if I understood his original correctly.  I have now tried changing the 58 to 62 but it did not result in anything saved in the target field.

About the default value... are you thinking it won't work because of the default being current user?  When I check the values in the variables of the tests, it did record the right values so I had high hopes it would work.

0 0
replied on September 18, 2020 Show version history

I have now also realized that "com" and "com2" are probably

  • Com = a temporary field to use as a collection of old and new
  • Com2 = the target collection field for Recorded Activities.

 

Still doesn't work, but does this color coding help you to see what is wrong?

0 0
replied on September 18, 2020

If I go to "Inspect" and the Console tab, I see four errors, all relating to getAttribute:

Uncaught TypeError: Cannot read property 'getAttribute' of undefined

0 0
replied on September 18, 2020

I have tried eliminating all but the ActionsNotesNew comments box (no change) and I tried changing the DateOfAction and PersonReporting field to fields that were just single line fields (no change) and I tried changing .getAttribute so that there was nothing between the brackets (no change).  

0 0
replied on September 18, 2020

$(document).ready(function () {
  var com = $('#q84 textarea').val();
//get previous comments    
  var RecordedActivities = $('#q58 textarea')[0].getAttribute();
//get previous action
  var ActionsNotesNew=$('#q62 input')[0].getAttribute();
//combine the information together
  var currentinfo=""; 
  if(ActionsNotesNew!=null){
        currentinfo=currentinfo+ActionsNotesNew;
      }
//append to field that displays the information
if (currentinfo!=""){
  com = com + '\n\n' + currentinfo;
  $('#q58 textarea').val(com);   
}
  $('#q58 textarea').attr('readonly', 'True');
});

 

0 0
replied on September 27, 2020

Hi Connie,

For default value, following is my setting to make the script working

0 0
replied on September 27, 2020

And the script should throw no error to work, how did you eliminate those error of getAttribute?

0 0
replied on September 28, 2020 Show version history

Thanks, Ziyan, for the additional information.  I may not have been using the same datasets as you.  I never did get any further with that set up.  I had reached out to a number of other people when trying to get it to work and received a slightly different option from another user that worked.  His JS looked very similar to yours.  I set mine up to match his and it worked so I presented that option to the users I'm creating the form for.

His differences:

  • His does not add the most recent comment, it just copies ALL comments each time.
  • His target fields to copy from are in a table, where as my original set up was a single line field for comments with the user and date (not in a table) since I didn't think we could target just the most recent table line.

 

I'm not sure why I couldn't get yours to work.  They both are so very similar, but ... I do appreciate you're working with me on this.  Here is the script I now have:

$(document).ready(function () {
         
  //When user completes the form, copy all notes to the multi-line notes field.
  $(".action-btn.Reject").on('click', function() {    
    copyNotes();
  }); 
  $(".action-btn.Submit").on('click', function() {
    copyNotes();
  }); 
  $(".action-btn.Approve").on('click', function() {
    copyNotes();
  }); 
 
  function copyNotes() 
  {
    var allNotes = '';
    $('.notesTable tr').each(function() {
      if ($(this).find('.notesDate input').val() != undefined) {
        allNotes = allNotes + $(this).find('.notesDate input').val() + ' - ' + $(this).find('.notesUser input').val() + ' - ' + $(this).find('.notesNotes textarea').val() + '\n'; 
      }
    });
    $('.multiLineNotesField textarea').val(allNotes);
  }
  
});

 

Test Run Comments (or Notes) Table:

And how it looks in the report with the targeted multiline field when you hover your mouse over that column field:

Thanks go out to Matthew Tingey for the final solution!

And thanks, Ziyan Chen, also!  I'm sure we were almost there!

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.