a!fileUploadField

I am using a!fileUploadField in my interface and its not showing any error when I am editing in expression Mode but when i change it to designer mode its showing error.

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!fileUploadField [line 78]:

                    a!fileUploadField(
                        label: "Upload An Image :",
                        labelPosition: "ABOVE",
                        target: cons!CS_DOCUMENT_FOLDER,
                        fileNames: fv!files.name: local!registratioNo,
                        fileDescriptions: "This is the uploaded file for the vehicle : " & local!registratioNo,
                        maxSelections: 1,
                        value: local!file,
                        saveInto: {
                          local!file,
                          a!save(ri!Vehicle.UploadedFile, save!value)
                        },
                        required: if((local!required), true(), false()),
                        validations: if(
                          fv!files.extension <> "JPG",
                          "File format is not supported ",
                          if(
                            fv!files.size > 1000000,
                            "File size should not be greater than 1 MB",
                            {}
                          )
                        )
                      )


no Code changes

  Discussion posts and replies are publicly visible

Parents Reply Children
  • Yes,
    Could please tell me what are the changes you made and why.

  • Ah! Actually, I was getting the same error. And very weird!

    It can be solved by putting an or() around your size validation as the fv!files property is an array even though you have a max selection of 1.

    Technically your check on the file extension should also use the or() although being a string it seems to handle it.

    Very weird though.

    if(
      or(fv!files.extension <> "JPG"),
      "File format is not supported ",
      if(
        or(fv!files.size > 1000000),
        "File size should not be greater than 1 MB",
        {}
      )
    )

  • 0
    Certified Lead Developer
    in reply to sivasuryap0002

    I don't see any errors myself yet, but I have a recommendation for how to correctly use the validations parameter.  The way you have it curently, the validations will only ever work one at a time.  In general, you should configure it such that any applicable validations are shown at any given time (such as if the file's extension is invalid AND it's too large).

    The key here is that "validations" expects an array of text - a single value will work fine but an array will work best.

    Oh, I also see your error now: your fileNames parameter is doing something invalid.  If you just want to use local!registrationNo for the file name, you would just use that and not invoke fv!files.name at all.  The way you currently have the code setup is not valid and I'm fairly sure it's the source of your error.

    Here's the overall corrected version:

    a!fileUploadField(
      label: "Upload An Image :",
      labelPosition: "ABOVE",
      target: cons!MY_FOLDER,
      fileNames: /* fv!files.name:*/ local!registratioNo,
      fileDescriptions: "This is the uploaded file for the vehicle : " & local!registratioNo,
      maxSelections: 1,
      value: local!file,
      saveInto: {
        local!file,
        a!save(ri!Vehicle.UploadedFile, save!value)
      },
      required: if((local!required), true(), false()),
      validations: {
        if(
          upper(fv!files.extension) <> "JPG",
          "File format is not supported ",
          {}
        ),
        if(
          fv!files.size > 1000000,
          "File size should not be greater than 1 MB",
          {}
        )
      }
    )

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Here's an alternative version of the code that should be runnable by simply copying and pasting:

    a!localVariables(
      local!registratioNo: "1234",
      local!file: null(),
    
      a!fileUploadField(
        label: "Upload An Image :",
        labelPosition: "ABOVE",
        /*target: cons!YOUR_TEMP_FOLDER,*/
        fileNames: /*fv!files.name:*/ local!registratioNo,
        fileDescriptions: "This is the uploaded file for the vehicle : " & local!registratioNo,
        maxSelections: 1,
        value: local!file,
        saveInto: {
          local!file,
          /*a!save(ri!Vehicle.UploadedFile, save!value)*/
        },
        /*required: if((local!required), true(), false()),*/
        validations: {
          if(
            upper(fv!files.extension) <> "JPG",
            "File format is not supported ",
            {}
          ),
          if(
            fv!files.size > 100,
            "File size should not be greater than 100 Bytes (note: I lowered this for testing purposes)",
            {}
          )
        }
      )
    )