cut out the name of a document

Hey all.

I have a validation in which the name of the uploaded attachment can't have more than 100 characters. I need that Appian automatically cut the name to maximum 100 characters.

I was trying to make an expression rule; I made an index to find the character number 101, I wanted to insert a "," to split the text and then remove it... but I can't because the insert function doesn't accept text for the index parameter.

Ideas?


Example value: nombredocumentosnombredocumentosnombredocumentosnombredocumentosnombredocumentosnombredocumentosnombredocumentos

  

  Discussion posts and replies are publicly visible

Parents
  • I think you need to understand what index() does -- when you give it a number as the second parameter, it attempts to return a corresponding array position from the source data.  Since a text string is really just an array of characters, it will return you the letter at that position of the string.  Note this isn't really a conventional use of index() (and not every function will treat a string as an array of characters), but that's what it's doing here, and from what I can tell it's totally unrelated to what you're really after.

    I believe you might have some success using the "fileNames" parameter of FileUploadField and your expression rule.  Personally, I'd opt instead to just use a user-facing validation similar to the following:

    a!localVariables(
      local!file: null(),
    
      a!fileUploadField(
        saveInto: local!file,
        value: local!file,
        maxSelections: 1,
        validations: {
          if(
            len(fv!files.name) > 5,
            "filename too long (5 characters for this example)",
            null()
          )
        }
      )
    )

    ...which will simply provide some feedback like this:

    However I assume (but haven't tried per se) that you could instead use the "fileNames" parameter as I mentioned to auto-truncate the filename - note that, as far as I can tell, the change doesn't happen until Form Submission time, so you'll need to experiment with it some.

    a!localVariables(
      local!file: null(),
    
      a!fileUploadField(
        saveInto: local!file,
        value: local!file,
        maxSelections: 1,
        
        fileNames: left(fv!file.name, 5)  /* insert your own length here */
        
        /*validations: {
          if(
            len(fv!files.name) > 5,
            "filename too long (5 characters for this example)",
            null()
          )
        }*/
      )
    )

Reply
  • I think you need to understand what index() does -- when you give it a number as the second parameter, it attempts to return a corresponding array position from the source data.  Since a text string is really just an array of characters, it will return you the letter at that position of the string.  Note this isn't really a conventional use of index() (and not every function will treat a string as an array of characters), but that's what it's doing here, and from what I can tell it's totally unrelated to what you're really after.

    I believe you might have some success using the "fileNames" parameter of FileUploadField and your expression rule.  Personally, I'd opt instead to just use a user-facing validation similar to the following:

    a!localVariables(
      local!file: null(),
    
      a!fileUploadField(
        saveInto: local!file,
        value: local!file,
        maxSelections: 1,
        validations: {
          if(
            len(fv!files.name) > 5,
            "filename too long (5 characters for this example)",
            null()
          )
        }
      )
    )

    ...which will simply provide some feedback like this:

    However I assume (but haven't tried per se) that you could instead use the "fileNames" parameter as I mentioned to auto-truncate the filename - note that, as far as I can tell, the change doesn't happen until Form Submission time, so you'll need to experiment with it some.

    a!localVariables(
      local!file: null(),
    
      a!fileUploadField(
        saveInto: local!file,
        value: local!file,
        maxSelections: 1,
        
        fileNames: left(fv!file.name, 5)  /* insert your own length here */
        
        /*validations: {
          if(
            len(fv!files.name) > 5,
            "filename too long (5 characters for this example)",
            null()
          )
        }*/
      )
    )

Children