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

Question

Question

Classic Cloud Form - Javascript not working as intended

asked on October 5, 2023

Hi Everyone!

We currently have a process that is on a self-hosted system and works fine, we have decided to move the process over to Cloud and we have been having some issues with the code on the process that is not working as intended. We are using the classic designer in cloud forms.

 

The process has 4 tables, CSS class Tablea, Tableb, Tablec, and Tabled. First when the form is loaded. Tablea and Tableb will run and check for duplicates in both tables and remove all duplicate values from the tables. Then Tablea and Tableb are compared with each other, when values from Tablea and Tableb match we remove the values from the two tables and insert the values in Tablec. Tabled is hidden with a field rule and radio button, when the button (CSS RAH) is selected Tabled is shown and when the table is shown it will compare data with Tablea, when it matches it will remove the data from Tablea.

We are having an issue when the data is removed by the code the values still reflect on the calculation fields, it's a basic SUM of the table values, and when the form is submitted and the next form loads with Tablea and Tableb some of the values that were removed are shown again in the tables. It seems like values are being cached and not removed completely/correctly.

 

Any help would greatly be appreciated!

 

$(document).ready(function () {

    var theLoading = '<div class="theLoading"><img src="https://media.tenor.com/On7kvXhzml4AAAAi/loading-gif.gif"></div>';

    $('#form1').append(theLoading);
    setTimeout(function () { $('.theLoading').fadeOut(); 
     
                      
                           }, 70);


    //$('.theLoading').show()
  
   
    $('.ro input').attr('readonly', 'True');
    $('.url').on('change', 'input', CheckDoc);

    var src;

    function CheckDoc() {

        var EntryID = $('.url input').val();
        src = "https://app.laserfiche.ca/laserfiche/DocView.aspx?repo=xxxxxxxxxxx&customerId=xxxxxxxxxx&id=" + EntryID + "#?openmode=PDF";
        $('.myframe iframe').attr('src', src);

    }

    setTimeout(addPreview, 1250);

    $('#q134').on('click', '.preview', function (event) {
        var theId = event.target.id;

        var theRow;
        var theObject = document.getElementById(theId);
        //theRow = document.getElementById(theId).closest('tr'); NOT FOR IE

        theRow = getClosest(theObject, 'tr'); //IE Alternative

        //console.log(theRow);
        var theTableClass = "LeavePayTBL";
        doIframe(theRow);
    });


    function doIframe(theRow) {
        var entryId = $(theRow).find('td:eq(2) input').val();
        $('.url input').val(entryId).change();//fullScreenButton 



    }

    function addPreview() {
        console.log('addPreview');
        $('#q134 table tbody tr').each(function () {

            var prevId = $(this).find('td:eq(4) input').attr('id');
            console.log(prevId);
            $(this).find('td:eq(4) input').after('<img class="preview" id="' + prevId + '" src="/Forms/img/np-formsubmission.png" height="24px"></img>')
            $(this).find('td:eq(4) input').remove();
        });
    }

    var ep = Element.prototype;
    ep.matches = ep.matches || ep.webkitMatchesSelector || ep.msMatchesSelector || ep.mozMatchesSelector;

    function getClosest(elem, selector) {
        while (elem !== document.body) {
            elem = elem.parentElement;
            if (elem.matches(selector)) return elem;
        }
    }




    $('.tablea').on('change', 'input', compareTables);
    $('.tableb').on('change', 'input', compareTables);
    $('.tablea').on('change', 'input', findDuplicateRows);


    setTimeout(compareTables, 3000);


    function findDuplicateRows() {
        var rowValues = "";
        var rowValsArray = [];
        $('.tablea tbody tr').each(function () {
            rowValues = $(this).find('td:eq(2) input').val() + $(this).find('td:eq(3) input').val();
            rowValsArray.push(rowValues);
        }); 
        findDuplicatesInArray(rowValsArray);
    }

    function findDuplicatesInArray(rowValsArray) {
        var dupcountarry = [];
        var count;
        if(rowValsArray.length > 1) {
            for(var i = 0; i < rowValsArray.length; i++){
                count=0;
                for(var j = 0; j < rowValsArray.length; j++){
                    if(rowValsArray[i]==rowValsArray[j]){   
                        count++;
                    }
                    dupcountarry[i]=count;
                }     
            }
        }
        for(var i = 0; i < dupcountarry.length; i++){
            if(dupcountarry[i]>1){
                $('.tablea tbody tr:eq(' + i + ')').find('.cf-table-delete').click();
            }
        }
  
    }

    var theRows = [];
    function compareTables() {
        theRows = [];
        
      $('.tablea tbody tr').each(function () {

            var oneDate = $(this).find('td:eq(1) input').val();
            var oneInvoicee = $(this).find('td:eq(2) input').val();
            var oneAmount = $(this).find('td:eq(3) input').val();

            theRows.push({ Date: oneDate, Invoice: oneInvoicee, Amount: oneAmount });
    
          
        });
        console.log(theRows)
        
      	var numberOfRows=0;
      
      	 $('.tableb tbody tr').each(function (){
           $(this).find('.cf-table-delete').click();
         
           var currDate = $(this).find('td:eq(1) input').val();
            var currInvoice = $(this).find('td:eq(2) input').val();
            var currAmount = $(this).find('td:eq(3) input').val();
            var isAppYes = $(this).find('td:eq(5) input').val();
            
           for(var i = 0; i < theRows.length; i++){

       					
                if (theRows[i].Invoice == currInvoice && theRows[i].Amount == currAmount && isAppYes == "Yes") {
                    var isalreadyThere = isAlreadyThere(currInvoice, currAmount);
                   if (isalreadyThere == false) { 
                 
                     $('.tablec .cf-table-add-row').click();
                     var firstRow = $('.tablec tbody').find('tr:last');
                  
                     $(firstRow).find('td:eq(1) input').val(currDate).change();
                     $(firstRow).find('td:eq(2) input').val(currInvoice).change();
                     $(firstRow).find('td:eq(3) input').val(currAmount).change();                   
                     $(firstRow).find('td:eq(2) input').attr('readonly','readonly');
                     $(firstRow).find('td:eq(3) input').attr('readonly','readonly');
                     $(firstRow).find('td:eq(1) input').attr('readonly','readonly'); 
                     $(firstRow).find('td:eq(4) input').attr('readonly','readonly');  
                     $(firstRow).find('td:eq(5) input').attr('readonly','readonly');  
                     
                     
                    $(this).remove();
                    deleteTblARow(currInvoice, currDate, currAmount);
                  }
                }

      		};

		});    
       
    }
  
  
    $('.tablec .cf-table-add-row').on('click', function(){
   	   var lastCRow = $('.tablec tbody').find('tr:last');
       $(lastCRow).find('td:eq(4) input').attr('readonly','readonly');  
       $(lastCRow).find('td:eq(5) input').attr('readonly','readonly');  
    });
 

   
  $('.RAH input').on('click', function () {
        if ($('.RAH input:checked').val() === 'Show') {
            RemittanceAdviceHistory();
        }
    });
    function RemittanceAdviceHistory() {
        theRows = []; 
           
        $('.tablea tbody tr').each(function () {
           var oneDate = $(this).find('td:eq(1) input').val();
           var oneInvoicee = $(this).find('td:eq(2) input').val();
           var oneAmount = $(this).find('td:eq(3) input').val();
           
            theRows.push({ Date: oneDate, Invoice: oneInvoicee, Amount: oneAmount });
        });
        $('.tabled tbody tr').each(function () {
            var currDate = $(this).find('td:eq(1) input').val();
            var currInvoice = $(this).find('td:eq(2) input').val();
            var currAmount = $(this).find('td:eq(3) input').val();
            for (var i = 0; i < theRows.length; i++) {
                if (theRows[i].Invoice == currInvoice && theRows[i].Amount == currAmount) {
                    deleteTblARow(currInvoice, currDate, currAmount);
                }
            }
        });
    }

    function isAlreadyThere(currInvoice, currAmount) {
        var isThere = false;
        $('.tablec tbody tr').each(function () {
            if (currInvoice == $(this).find('td:eq(2) input').val() && currAmount == $(this).find('td:eq(3) input').val()) {
                isThere = true;
                console.log("---true");
            }
        });
        return isThere;
    }

    function deleteTblARow(invoiceNo, currDate, currAmount) {
        console.log('Deleting', invoiceNo);
      
        $('.tablea tbody tr').each(function () {
            if ($(this).find('td:eq(2) input').val() == invoiceNo && $(this).find('td:eq(3) input').val() == currAmount) {
                $(this).remove();
              
            }
        });
    }

    function deleteTblAOneRow(invoiceNo, currDate, currAmount) {
        console.log('Deleting', invoiceNo);
      
      	$('.tablea tbody tr').each(function () {
            if ($(this).find('td:eq(2) input').val() == invoiceNo && $(this).find('td:eq(3) input').val() == currAmount) {
                $(this).remove();
            }
        });
    }
  
$(document).ready(function(){
$('.hideSubmit input').on('change', function(){
  if($(this).val() == 0){
  $('.Submit').removeAttr('disabled');
  } else {
    $('.Submit').attr('disabled', 'disabled');
  }
})
});
});



 

0 0

Replies

replied on October 10, 2023

If it is convenient for you, could you please tell us the process file that is the cause of the problem so that we can help you with the troubleshooting?

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

Sign in to reply to this post.