Help with simple script

Viewing 1 reply thread
  • Author
    Posts
  • April 30, 2022 at 10:25 PM #47204

    Michael Tucker
    Participant

    I have fields just two fields that need to operate in a form….

    ShareSell$Amt (numeric, id:fld-89c6961ad2ec43e8853ff13e052fc807)
    NextRung$Amt (calculation, id:fld-276de1515a7c4054b9df9410cbbefd29)

    I just want after a find of the fields involved, to run a script to
    read in the first found record field NextRung$Amt,
    move to the next record and insert that read amount into field ShareSell$Amt,
    then continue thru the found set of records.

    The first record has the beginning ShareSell$Amt that is calculated in the record as NextRung$Amt.

    The function I’m looking for — is that number from the field NextRung$Amt is picked up and put into the next record’s ShareSell$Amt, and that makes that record calculate a new NextRung$Amt, which is picked up and put into the next record, then on until records in the found set run out.

    This script just stops on the first record, so it needs something.

    function Calc_NextRung_LADDER4() {
    	let balance = 000000;
    	var nextrung_id = 'fld-276de1515a7c4054b9df9410cbbefd29';
    	var newsharesell_id = 'fld-89c6961ad2ec43e8853ff13e052fc807';
    	//var transaction_date_id = 'fld-2567fc59b0ce45f982f2fe2d20eb0d79';
    	//need a saved find 'Calc_Balances LADDER4'
    	//Sam Moffatt, Tap Forms Forum, 10/21/2019 #37289
    	
    	for(record of form.getSearchNamed('Calc_Balances LADDER4').getRecords())
    	{
    		balance += record.getFieldValue(nextrung_id);
    		record.setFieldValue(newsharesell_id, balance);
    	}
    	document.saveAllChanges();
    }
    
    Calc_NextRung_LADDER4();

    In the screenshot, this set has 8 records or “rungs”. Theoretically the script would populate the 7 following rungs or records after the amount is first set to begin in the first record.

    Thanks for those that make these things easy for those of us who infrequently dabble in scripts,
    Mike

    • This topic was modified 2 years, 6 months ago by Brendan.
    Attachments:
    You must be logged in to view attached files.
    May 5, 2022 at 11:02 PM #47222

    Brendan
    Keymaster

    Hi Michael,

    I added back-ticks around your code so it’s easier to read.

    That looks like it should work. But record is a keyword that means to use the currently selected record. In the script I would change record to rec or something like that. See if that solves the problem.

    Thanks,

    Brendan

Viewing 1 reply thread

You must be logged in to reply to this topic.