Table default values

Viewing 11 reply threads
  • Author
    Posts
  • January 24, 2022 at 8:00 AM #46415

    John McArthur
    Participant

    Hi,

    Is there a way of creating a default value within a Table so that when a new Line is added (with a ‘Web site’ type) part of the link is already populated?

    Thanks

    January 24, 2022 at 8:20 AM #46416

    John McArthur
    Participant

    Sorry! Silly me not scrolling down far enough to see the ‘default field’! Doh! :-)

    January 24, 2022 at 8:38 PM #46418

    Brendan
    Keymaster

    No worries. Glad you found the solution.

    January 25, 2022 at 8:50 AM #46423

    John McArthur
    Participant

    Hi,

    Just a quick question…Tables – Is there a way to have the ‘Web Site’ icon appear at the front of the links?

    (I assume this is the only way to activate the link as double clicking doesn’t appear to do anything)

    I have some particularly long addresses so it would be nice to trigger the link from the start of the field instead of at the end.

    Thanks

    January 25, 2022 at 10:01 AM #46425

    Daniel Leu
    Participant

    Hi John, I run into the same issue…. I created a toggle field in the first column. Then I added a field script that is triggered by this checkbox field. When the checkbox is set, then the file is opened. This way, I no longer have to look for the globe at the end of the URL.

    I did add an additional field that only displays the filename since in don’t care about the file path in my case.

    Set open_id and link_id values according to your form. open_id is the id of the checkbox flag that triggers the script and link_id is the id of the website field that contains the URL of your file.

    function Attachment_Open() {
    
    	const open_id = 'fld-xxx'; // checkbox Id
    	const link_id = 'fld-xxx'; // URL Id
    
    	let open = record.getFieldValue(open_id);
    	let link = record.getFieldValue(link_id);
    	
    	if (link && open){
    		link = link.replace(/[ ]/g, '\ ')
    
    		console.log("Opening URL " + link);
    		Utils.openUrl(link);
    
    		// clear opening flag
    		record.setFieldValue(open_id, false)
    		form.saveAllChanges()
    	}
    }
    
    Attachment_Open();

    At the end, I clear the checkbox flag so it doesn’t stay checked.

    January 26, 2022 at 5:17 AM #46449

    John McArthur
    Participant

    Hi Daniel,

    Thanks for your suggestion.

    Can I assume that I don’t need to amend (‘replace’ code) the link address as it’s already in the correct format within the field?

    Thanks

    January 26, 2022 at 10:04 AM #46452

    Daniel Leu
    Participant

    Hi John, yes, this script assumes that the link address is already in the proper format. If clicking on the globe works, then the script will be able to open the file as well.

    January 26, 2022 at 4:04 PM #46456

    John McArthur
    Participant

    Hi Daniel,

    I attempted your script with the appropriate FLD’s inserted for the toggle switch & link but couldn’t get it to work.

    The links work fine when using the Globe but when the Toggle box is ticked nothing happens.

    Tested the script via the console and the variables were returning; ‘open’ = ‘false’, even when ticked & ‘link’ = ‘undefined’, even though link field was populated with a valid link.

    Just to make sure I have created the Table correctly; it should have a toggle field, a link field and a script field with your script inserted?

    I’m probably doing something very wrong as usual! (Pesky newbies!) :-)

    January 26, 2022 at 5:26 PM #46458

    Daniel Leu
    Participant

    Hi John,

    Did you set the two constants accordingly?

    	const open_id = 'fld-xxx'; // checkbox Id
    	const link_id = 'fld-xxx'; // URL Id

    Yes, the table has at least the three fields you listed.

    January 26, 2022 at 5:52 PM #46459

    John McArthur
    Participant

    Hi Daniel,

    Yes, to ensure I got the correct ones, I retrieved them specifically whilst in the JavaScript view, from the ‘Available Fields’ ID section.

    Noticed some semi-colons missing so added them. Is this correct?

    This is the code:

    function Attachment_Open() {

    const open_id = ‘fld-4b19c3623b674f13b6d07093f0889cf0’; // checkbox Id
    const link_id = ‘fld-2a2a101bee1e439cbbe098a8051a57fb’; // URL Id

    let open = record.getFieldValue(open_id);
    let link = record.getFieldValue(link_id);

    if (link && open){

    console.log(“Opening URL ” + link);
    Utils.openUrl(link);

    // clear opening flag
    record.setFieldValue(open_id, false);
    form.saveAllChanges();
    }
    }

    Attachment_Open();

    January 27, 2022 at 12:14 AM #46462

    Daniel Leu
    Participant

    Semicolons are optional. Adding them doesn’t hurt.

    Would you mind to share your TF template? If you don’t want to do it publicly, you’ll find my contact infos in my profile.

    January 27, 2022 at 8:15 AM #46467

    John McArthur
    Participant

    Hi Daniel,

    I have decided to go down the keep it simple route! (A bit of lateral thinking)
    Once all my data fields have been populated, I can simply reduce the length of the field display dramatically as this will still show the Globe but only a fraction of the link.
    As you mentioned earlier, I too don’t need to know the full link value.
    I’ll just put a Title/Item field in to show a brief description of the file/folder and that should work fine.

    Many thanks for your help but I didn’t want to waste any more of your time on such a small part of my ‘big picture’. :-)

    Cheers.

Viewing 11 reply threads

You must be logged in to reply to this topic.