Data needs to be stored in line by line

in a paragraph field i will provide input as 

test1

test2

test3

How this data will be stored in db ,is it will be in line by line as separate string or as a single string

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    If I understood correctly, you want to store these as separate line items in the DB but have them in one paragraph field in the interface?

  • 0
    Certified Senior Developer
    in reply to Tabassum

    Hello ,

    You can try using the below format. But you will have to construct the data for each line value and map your Parent record/data PK here and also try to have a sort/order value using the indexes, so that the text entered is always displayed in the correct order. 

    a!localVariables(
      local!save,
      local!update:if(
        a!isNullOrEmpty(local!save),
        {},
        reject(
          fn!isnull(_),
          split(local!save,"
    ")
        )
      ),
      {
        a!paragraphField(
          label: "Paragraph",
          labelPosition: "ABOVE",
          value: local!save,
          saveInto: local!save,
          refreshAfter: "UNFOCUS",
          height: "MEDIUM",
          validations: {}
        )
      }
    )

  • 0
    Certified Lead Developer
    in reply to Tabassum

    Split them using the split function and then run a!forLoop() in it to construct a CDT for every item the split() function returned. 

  • = a!localVariables(
      local!emails: ri!emailAddresses,
      local!invalidEmails: if(
        isnull(local!emails),
        {},
        joinarray(
          reject(
            isnull(_),
            a!forEach(
              items: split(local!emails, " "),
              expression: if(
                regexmatch(
                  pattern: "^[A-Z0-9\'\+\&\%_-]+(\.{0,1}[A-Z0-9\'\+\&\%_-]+)*[@]{1}[A-Z0-9.-]*[A-Z0-9-]+[.]{1}[A-Z]{2,6}$",
                  searchString: fv!item,
                  regexFlags: "si"
                ),
                null,
                fv!index
              )
            )
          ),
          ","
        )
      ),
      local!validation: if(
        isnull(local!invalidEmails),
        {},
        "Invalid email at " & local!invalidEmails & " position(s) "
      ),
             a!paragraphField(
                            label: "Email Addresses",
                            labelPosition: "JUSTIFIED",
                            placeholder: "Email Addresses should be one per line (can be pasted from Excel)",
                            value: ri!emailAddresses,
                            saveInto: ri!emailAddresses,
                            refreshAfter: "UNFOCUS",
                            height: "TALL",
                            required: true,
                            validations: local!validation
                          )
                          )


    Hi   /   ,this is my code where i will be pasting /entering email addresses in line by line  in paragraph field . so i want to have 2 validations where 1st validation checks for line delimiter and 2nd validation for email format .

    How the emailaddresses are saved in dB  is it line by line only ?

    I should pass this email addresses to an api in line by line .can you please suggest how to validate those emails and then pass it to api line by line. 

  • emailAddresses is one of  text field in CDT and when entering the values in paragraph field it is storing the data in rule input of that cdt as shown below




  • 0
    Certified Senior Developer
    in reply to Tabassum

    Could you please try the below changed code. Also you can create a rule to do the separation of email ids and call it in your API and as well as here to validate the email addresses. so that you don't have to worry about validating while using this string anywhere else. You can handle it in the interface and make sure the user does not submit an invalid list of email addresses. In this way you don't have to worry about how it is saving in your DB. Because users can enter in  different ways. So, I recommend make use of email identifiers such as .com to find where your text has to be broken into different parts instead of relying on spaces or any other values.

     

    = a!localVariables(
      local!emails: ri!emailAddresses,
      local!individualMail: if(
        a!isNullOrEmpty(local!emails),
        {},
        reject(fn!isnull(_), split(local!emails, "
    "))
      ),
      local!invalidEmails: substitute(
        tostring(
          reject(
            fn!isnull(_),
            a!forEach(
              items: local!individualMail,
              expression: if(
                validateemailaddress(fv!item),
                null,
                fv!index
              )
            )
          )
        ),
        ";",
        ","
      ),
      local!validation: if(
        isnull(local!invalidEmails),
        {},
        "Invalid email at " & local!invalidEmails & " position(s) "
      ),
      a!paragraphField(
        label: "Email Addresses",
        labelPosition: "JUSTIFIED",
        placeholder: "Email Addresses should be one per line (can be pasted from Excel)",
        value: ri!emailAddresses,
        saveInto: ri!emailAddresses,
        refreshAfter: "UNFOCUS",
        height: "TALL",
        required: true,
        validations: local!validation
      )
    )


  •  : I have used your above code but getting invalid email even though it is in email format .

  • 0
    Certified Senior Developer
    in reply to Tabassum

    Not sure why. I am not getting any errors for the same email address. Could you please share your rule/local variable section with the data. and what is the type for the rule input.


Reply Children