You are viewing limited content. For full access, please sign in.

Question

Question

Update Field When Deleting Record in a Collection

asked on May 15 Show version history

Hi all, I'm trying to update fieldId: 190 when deleting a record in collection. The count in RU Count is trigger by FieldID : 75. Here code:

LFForm.onFieldChange(function() {
    var fieldValues = LFForm.getFieldValues({ fieldId: 75 });

    // Check if fieldValues exist and are not empty
    if (!fieldValues || Object.keys(fieldValues).length === 0) {
        console.warn("No values found for fieldId 75.");
        return;
    }

    // Convert to array (including duplicates)
    var allValues = Object.values(fieldValues);

    // Remove duplicates
    var uniqueValues = [...new Set(allValues)];

    // Destructure first three unique values with fallback to null
    const [value0 = null, value1 = null, value2 = null] = uniqueValues;
  
  LFForm.setFieldValues({fieldId: 190}, allValues.length);

    // Logging
    console.log("First 3 Unique Values:", value0, value1, value2);
    console.log("All Values:", fieldValues);
    console.log("Total count (including duplicates):", allValues.length);
    console.log("Unique values count:", uniqueValues.length);
}, { fieldId: 75 });

 

Travel 1.png
Travel 2.png
Travel 1.png (52.74 KB)
Travel 2.png (65.77 KB)
0 0

Replies

replied on May 16

Hola Mr. Matthew. My mind set is JavaScript. BUT, i'm actually all for formula functions. If this or anything can be done with formulas then Yes I would rather use formulas for any project or task. So, that being said, I'm going to looking into formula before I ask, "How can I do this......".

Thanks a Million!!!!

1 0
replied on May 16

It’s definitely a mentality shift from the Classic Designer where you just kind of assumed you would have JS for a lot of things to the Layout Designer saying “what did I used to do in JS that I can now do with built-in stuff?”

0 0
replied on May 16 Show version history

Well, I found it. Helloooo, it was to obvious. Use the Count function. I should just delete this post. But I'm not. I'm sure this is someone out there that might run into this mentality issue. LOL

I need to stop thinking that JS is the key to resolving everything.

Thanks again.

1 0
replied on May 15

I’m curious why you are doing this via Javascript instead of a formula.

There is no event that is triggered by the addition or deletion of records in a table or collection.  The usual workaround for that is to have a field that populates the count via formula - and changes to that field triggers the Javascript.  So once again we’re at formulas.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.