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

Question

Question

Collection set won't preserve when all rows are deleted

asked on August 7, 2023 Show version history

Hi all, this is using LF Cloud:

 I have a goofy anomaly in which a Collection will not preserve throughout my Business Process when all rows are removed. 

 Step 1, Form 1: Add Employees:


 Step 2, Form 2: Remove Employees (this example I removed two to show this works)

Step 3, Form 3: Collection shows two employees remaining

Now, if I remove all rows in Step 2, Form 2:

It does not retain ANY removal in Step 3, Form 3:

 

I was thinking initially this could be a disabled field error (as I have JS that disables / enables forms on field changes), but it seems I've replicated the circumstances down to this instance.

 

 Perhaps it has something to do with how collections are stored as empty object -> single string -> array in Laserfiche? (side note: now I just convert all single set items into arrays to make the JS more manageable)

 Because I'm on Cloud, I can't think of a reasonable way to use LFForms to interact with this (because the ways you can interact with Collections are limited).

 Maybe I could make a radio button in Form 2 to enact a ruleset in Form 3 to Hide the collection and ignore the data when hidden, but that's about all I can think of (would that then effectively make the set empty??).

 

 Collection Settings are:
 Form 1: range of sets [0 min, 500 max]

 Form 2: range of sets [0 min, 500 max] (enables editing, adding , deleting)

 Form 3: append set [0 min, 0 max] (prevent adding)

 

 Appreciate any help, thanks!

 UPDATE: My Radio button effort does not clear the collection set data, as I have some Javascript that injects an HTML Table using the collection field data. Suppose I could add a variable to fetch the Radio Button field value when executing the LFForm JS.



UPDATE 2:  I am able to use the radio button field to substitute the field values I pulled as an empty set. The only issue I have with this is that it could be confusing for a form user with yet another extra field. If they delete all the rows using the X's, they shouldn't have to click an extra button.

 

NOTE: My Ruleset in Form 3 is actually confined to hiding the Collection, and not each Item in the Collection Set. Reason being is I have other pre-existing rules, and having multiple rules on the same field is advised against.

NOTE 2: This workaround isn't fully complete either. Because the Collection Set still retains the data, altering the template fields becomes more cumbersome.

0 0

Answer

SELECTED ANSWER
replied on October 10, 2023 Show version history

Final Update:

This is the closest I could get it...

After playing intensely with manipulating fields inside a collection set, I came up with this code:

function emptyExceptOne () {

    console.log("emptyExceptOne() called")

    let empty = LFForm.getFieldValues(_EmptyCollection)['value']

    if (empty == "YES") {

        console.log("deleting..")

        for (let i=0; i<collectionSize()-1; i++) {LFForm.deleteSet(_Collection, 0)}

        let collectionFields = [..._CollectionFields].filter(item => item !== _Collection);

        console.log("editing..")

        for (let i=0; i<collectionFields.length; i++){LFForm.setFieldValues(collectionFields[i], "_ALL REMOVED_")}

    }

}

This way I can somehow represent in the metadata all the fields were removed. If at least one Set remains, the collection will preserve across forms. You could alternatively use "_AllRemoved_" instead of an empty string "".

0 0

Replies

replied on September 29, 2023

UPDATE:

 I have half of a solution:

 Using some JavaScript I can at least hide the entire collection on Form Submission:
 

// Revert Disabled Fee Fields So Form Saves Them:
LFForm.onFormSubmission(() => {
  let collectionResult = deleteCollection()
  console.log("collectionResult:", collectionResult)
  if ( collectionResult.length == 0 ) {
    LFForm.showFields(removeAllEmployees)
    LFForm.setFieldValues(removeAllEmployees, {value: "Yes"});
    console.log("EMPTY!", LFForm.getFieldValues(removeAllEmployees)); 
    LFForm.hideFields(employeesCollection)
  }
});
// */

// /* Attempt to Fix Collection Rows Bug
console.log("Initial Length:", LFForm.getFieldValues(employeeName))
function deleteCollection () {
	let collection = LFForm.getFieldValues(employeeName)
    if (typeof(collection) == 'string') collection = [collection]; 
    return collection
}
// */

However, even though the collection is indeed hidden throughout the rest of the form... The form still saves the Collection (prior to being emptied) and retains the emptied metadata...

Kind of wish the LFForm.hideFields had an option to ignore the data... I think that's where I can't find a good solution.

 Suppose I'll keep my input button and just return an error so the user can manually click it.

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

Sign in to reply to this post.