Automatically setting line number script not working

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Automatically setting line number script not working

Viewing 5 reply threads
  • Author
    Posts
  • March 15, 2021 at 2:12 AM #43846

    Victor Warner
    Participant

    This is a message for Sam Moffat concerning his video (https://www.youtube.com/watch?v=Juwt0OGoEkc) where he provided a script to automatically add an incremental number (from 14:14 in the video).

    I have tried to replicate exactly what is shown in the video, but on adding a new record does not insert a number as Sam’s video shows.

    Here is the script I created:

    function Auto_Line_Number() {
    
    	var orders = record.getFieldValue('fld-01d4dcc690be4cfab6e634f78da8e568');
    	var line_items = orders.getFieldValue('fld-fd35beba82334d6586f354d914eb1857');
    	
    	console.log("found autoline number entries: " + line_items.length);
    	
    	var line_number = record.getFieldValue('fld-5d11f80da2e04cadbb82b52829e1be8c');
    	
    	if (line_number){
    	
    		record.setFieldValue('fld-5d11f80da2e04cadbb82b52829e1be8c', line_items.length);
    		
    		document.saveAllChanges();
    		return "updated line number to " + line_items.length;
    	
    	}
    	
    	
    	return "Did not update line number, already set";
    
    }
    
    Auto_Line_Number();

    Attached is the Tap Forms database.

    Help would be gratefully received.

    Attachments:
    You must be logged in to view attached files.
    March 15, 2021 at 8:40 PM #43851

    Brendan
    Keymaster

    Hi Victor,

    Unfortunately the .tfarc file doesn’t contain the Orders form. Can you send that too? A Tap Forms Archive works from the top-down to include sub-forms. But it doesn’t export from bottom-up. It doesn’t export parent forms but it does export child forms.

    March 16, 2021 at 1:17 AM #43861

    Victor Warner
    Participant

    Brendan,

    Thank you. Full version now attached.

    Attachments:
    You must be logged in to view attached files.
    March 16, 2021 at 7:57 AM #43863

    Sam Moffatt
    Participant

    This line:

    if (line_number){
    

    needs to read:

    if (!line_number){
    

    Because we want to update the line number when the line number is not set. The ! character is a logical NOT operator, so we’re turning line_number from false (when the field isn’t set) to be true to pass the if statement.

    March 24, 2021 at 4:10 AM #43921

    Victor Warner
    Participant

    Sam,

    Thank you. I looked at your video first on a 11inch iPad Pro the ! did not come through clearly…

    March 24, 2021 at 10:24 PM #43926

    Sam Moffatt
    Participant

    Yeah, I need to get better at scaling up the code font size on the recordings and probably cross posting over to the forum the final code.

Viewing 5 reply threads

You must be logged in to reply to this topic.