Skip to main content
Known Participant
Jan 3, 2024 9:45 AM UTC
Question

Checking if all documents in a list have the same extension without using forEach()

Hi,

Currently have a rule containing the following where the rule input is a list of documents and constant has text "DOCX"

return true if all document extensions in a list have the extension "DOCX" otherwise return false.

and(
a!forEach(
items: ri!receivedDocumentsList,
expression: document(
fv!item,
"extension"
) = cons!DOCUMENT_EXTENSION_DOCX
)
)

Which works fine but is there a more elegant way to do this?

Regards

    6 replies

    konduruc733182
    Inspiring
    Jan 3, 2024 10:23 AM UTC

    Hello pauls0008,

    Where are you calling this expression rule? What are you looking for exactly? Have you tried creating a separate rule with the validation that you are using and use apply() instead?

    pauls0008Author
    Known Participant
    Jan 3, 2024 10:35 AM UTC

    Hi,

    The rule is to be called from a process model in an xor node. Depending on the boolean value returned to the process model different processing then takes place.

    In this first iteration of the rule development a constant is being used but this would be replaced in time by another rule input to allow any extension to be checked.

    I had thought of apply() but saw this....

    Regards

    konduruc733182
    Inspiring
    Jan 3, 2024 10:50 AM UTC

    But why handle this in Process model? Have you tried to filter it in the UI and have different saves for the types other that DOCX? Not sure what is the alternate process that you have if the file is not of docx. 

    stefanhelzle0001
    Brainy
    Jan 3, 2024 11:10 AM UTC

    a!localVariables(
      local!fileExtensions: {"docx", "DOCX", "PDF"},
      all(exact(_, "DOCX"), upper(local!fileExtensions))
    )

    pauls0008Author
    Known Participant
    Jan 3, 2024 5:26 PM UTC

    Thank you guys for the replies that have helped this move forwards.

    mikes0011
    Brainy
    Jan 3, 2024 5:54 PM UTC

    I come from a time before a!forEach(), and trust me when I say, it is the "elegant" way.

    The Expression Guru