Previous Record Script

Viewing 2 reply threads
  • Author
    Posts
  • December 22, 2024 at 7:39 PM #51405

    Glen Forister
    Participant

    I used this before with rain and it works in that Form. I copied the working script for rain and used it here.
    I changed the fld- numbers to be for this form.
    The calculations seem to be doing something unexpected.
    Please tell me what is wrong?

    If you get this to work, another question is how do I get the total sum from one record displayed in the next record?
    In each record I want to show
    Today’s hours
    Yesterday’s total hours
    Today Total hours (which is the sum of the above.

    I like to see these so I know the math is working and I can easily check.

    Attachments:
    You must be logged in to view attached files.
    December 23, 2024 at 6:29 PM #51407

    Daniel Leu
    Participant

    Hi Glen,

    Set the return type of your Today & Previous script to number! As text, it concatenates the fields instead of adding them.

    Here’s the yesterday’s hours script:

    function yesterdays_hours() {
    	
    	var records = form.getRecords();
        	var currentRecordIndex = records.indexOf(record);
    
        	if (currentRecordIndex > 0) {
            	var previousRecord = records[currentRecordIndex-1];
        	} else {
         		return 0;
        	}
    	
    	var today_hours_id = 'fld-7ecb8ad8fe3a4b6db80ea939a60accb2';
    	var yesterday = previousRecord.getFieldValue(today_hours_id);
    	
    	console.log("Yesterday: " + yesterday)
    
    	return yesterday;
    }
    
    yesterdays_hours();
    December 23, 2024 at 7:33 PM #51408

    Glen Forister
    Participant

    I think I got it to work by using the above for one field and today for another and combined the 2 fields. Simplifies it with an additional field.
    Thanks.

Viewing 2 reply threads

You must be logged in to reply to this topic.