Strategy for populating fields

Viewing 2 reply threads
  • Author
    Posts
  • January 27, 2022 at 8:22 AM #46468

    Kirk Williams
    Participant

    Good morning!

    I know populating fields conditionally (based on other fields’ values) is a popular topic, so I’m posing this question as more of a plea for strategic guidance. As I’m sure will become painfully obvious, my experience with coding is entry-level at best.

    The file I’m working with is a pretty basic asset inventory. The example I’ll use is: populating (multiple) spec fields based on the value of another (model) field.

    When adding a new device to my “Computers” form, I need to include specific specifications such as “RAM”, “HD”, “Format”, “OS”, etc. (obviously there are many more).

    Entering these values manually is not only cumbersome but also repetitive since I am often deploying multiple devices with the same characteristics. My goal is to be able to enter a value in the “model” field and have the spec fields automatically populate with that model’s corresponding values.

    To accommodate this, I’ve created a “Computer Models” form containing records for each model and their respective specs. On my “Computers” form, I have a link-to field (“Linked model”) that allows me to select a record from “Computer Models”.

    So here’s where I feel as though I need some strategic assistance. With guidance from other users here, I added script fields that will populate “spec” values based on the “Linked model” value. For example, the “Format” field contains the following code:

    function getFormat() {

    var Format = 'fld-20f1f5ca216a4d7f8108f32be30c22d3';
    var linked_model = record.getFieldValue('fld-a136f05b49a54749b15bedd371560ce1');

    if (linked_model.length > 0) {
    var first_contact = linked_model[0];
    Format = first_contact.getFieldValue('fld-20f1f5ca216a4d7f8108f32be30c22d3');
    }

    return Format;

    };

    getFormat();

    I was elated to see this successfully recognize/return the format for the chosen model, however, I’ve since observed some less-than-optimal behavior with this method:
    1. The “Linked model” value is not visible or editable in multi-column view. For visual representation, I’ve addressed this by simply adding an additional “Model” field and populating it with the text value using the same scripting method as the other spec fields. This solves the visibility issue, but still does not allow me to add/edit records in multi-column view (which I tend to do often).
    2. If a record’s “Linked model” field does not have a value entered, the scripted “spec” fields display the referenced field ID. Having fld-20f1f5ca216a4d7f8108f32be30c22d3 displayed results in a distracting/confusing visual representation. Ideally, I’d like the scripted fields to remain blank (or return a default vale like “unspecified” etc) in this scenario.
    3. Selecting a record in the “Linked model” field feels cumbersome. This is not a huge inconvenience, but ideally, I’d love to be able to enter this value using my keyboard, as I would if it were a text or pick list selection. Currently, I’ve only been able to select a linked record by clicking on “Select existing linked records” and scrolling through the “Computer Models” records.
    4. Exported data displays scripted fields in the same way multi-column view does. Exported records offer the same display as described in item #2 above.

    I’ve seen and tinkered with other methods, including IF/THEN and SWITCH statements, but haven’t been successful at all. Since I’m honestly not sure if my issues are with coding or the core logic behind my strategy, so I’m kneeling before the TapForms gurus here with a plea for guidance.

    Any suggestions or new perspectives on my situation are welcomed and sincerely appreciated!

    Thanks in advance!

    January 27, 2022 at 3:43 PM #46480

    Sam Moffatt
    Participant

    1. For the first one, if you’re using script or calc fields then they won’t be editable in the multicolumn view. The not visible could just be the field not being selected in your MCLV settings so make sure you check that. That said, if you want to edit the values differently from the model, it sounds like maybe you want to copy default values across which then you can edit later which would be a copying sort of use case? I have a video on a copying use case with link to form fields that might help.

    2. The return Format is what is triggering the field ID to be displayed because your first line sets Format to the field ID, I’ll put a fix for your script below. If you’re using 1:M link to form (from what it looks like maybe not?) then you can use calculation fields to copy values. In this model I’d have a Link to Form 1:M from “Computer Models” to “Computers” with “Show Inverse Relationship” ticked which should let you get single values out.

    3. I could have sworn that interface for existing records had a search box in it but that might only be on the Mac and not on iOS. That might also just be the single select side of the 1:M link type too.

    4. If you fix the field that should fix the print.

    This will fix the format being the field ID:

    
    function getFormat() {
        var Format = '';
        var linked_model = record.getFieldValue('fld-a136f05b49a54749b15bedd371560ce1');
    
        if (linked_model.length > 0) {
            var first_contact = linked_model[0];
            Format = first_contact.getFieldValue('fld-20f1f5ca216a4d7f8108f32be30c22d3');
        }
    
        return Format;
    }
    
    getFormat();
    

    If you end up changing the link around to do 1:M from the Computer models and don’t use the calc field then you’ll have to change this to be just if (linked_model) and you can just use linked_model.getFieldValue.

    February 3, 2022 at 6:46 AM #46588

    Kirk Williams
    Participant

    Thank you so much Sam! I will definitely need to spend some time with this (given my limited scripting experience), but this is precisely the type of logistic advice I was hoping for.

    Your time and guidance are very much appreciated!

Viewing 2 reply threads

You must be logged in to reply to this topic.