How to validate user input with MS SQL Table ?

Hi Community,

I have a user input task on my site. User fills the data and the data goes into MS SQL table.

I have a field (say PR No.) in my form. I want to validate the the data entered by user in the PR filed on the fly with my table to check whether PR No. entered by user exist in my table or not ?

How can i do it ?

 

Thanks for your help.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • Hi default memory size is 1 MB mentioned in the link. Instead of bringing PR No list in memory from external DB, isn't it better to pass the user entered PR number on the form (interface) as a parameter to my query rule and then check whether PR number exist or not and return appropriate message based on true/false value ?
  • 1)Then write a query entity which fetch the PR table which has rule input PR No,with query filter
    a!queryFilter(
    field:"PR No",
    operator:"=",
    value:ri!PRNo
    )
    2)pass the user entered PR number for the above rule
    3)if that rule returns data then the PR No is exists in that table
    if total count of that rule is 0 then the Pr No is not Exists.
  • Hi  i know the concept now but need help with syntax. I have created the Query Rule CheckPRNumber() and if i pass the PR number as parameter then it returns the value.

    The same Query Rule i am trying to call in my interface like this - 

    a!integerField(
          label: "PR",
          labelPosition: "ABOVE",
          value: ri!PRnumber,
          saveinto: ri!PRnumber,
          refreshAfter: "UNFOCUS",
          validations: {if(rule!CheckPRNumber(ri!PRnumber), {}, "Invalid PR Number")}
        )

    But i am getting error - Error evaluating function 'queryruleexec' : No value received for input [PRnumber] in query rule [CheckPRNumber].

  • create query rule as CheckPRNumber with below logic.

    a!queryEntity(
    entity: cons!(Constant which refers your Pr NO Entity),
    query: a!query(

    filter : if(
    isnull(ri!PRNo),
    null,
    a!queryFilter(
    field :"PRNo",
    operator:"=",
    value :ri!PRNo
    )
    ),
    pagingInfo:a!pagingInfo(
    startIndex: 1,
    batchSize: - 1
    )
    )
    )

    this rule " rule!CheckPRNumber(ri!PRnumber)" returns empty data if data is not their for that PRNo,Now  you can check with length or totalcount for validation

    a!integerField(
    label: "PR",
    labelPosition: "ABOVE",
    value: ri!PRnumber,
    saveinto: ri!PRnumber,
    refreshAfter: "UNFOCUS",
    validations: if( isnull(PRnumber),{},

    if(rule!CheckPRNumber(ri!PRnumber).totalCount=0,{},"Invalid PR Number"

    )

    )
    )

  • Hi  ,

    Thank you for your suggestion. I fixed the problem this code - 

    a!integerField(
          label: "PR",
          labelPosition: "ABOVE",
          value: ri!PRnumber,
          saveinto: ri!PRnumber,
          refreshAfter: "UNFOCUS",
          validations: {
        if(
          isnull(ri!PRnumber),
          {},
          if(
            length(rule!CheckPRNumber(ri!PRnumber)) = 0,
            "PR Number does not exist.",
            {}
          )
        )

  • Hi my requirement has been changed now. I am looking for your suggestion. Now my PR field on form can have more than 1 PR number and user can separate them using comma (,) (for ex- 123,234,456 where 123 is a PR number. Similarly 234 and 456). Earlier i was checking for only 1 PR number but now i want to validate for all the PR numbers that user enters. Also maximum, a user can enter 20 PR numbers. Is there any way to implement this ? What approach would you suggest ?
  • Hi prais1852
    You have to make
    your rule input as array ,
    Earlier you have only one validation rule which checks the valid PR Number,now you have to write two more validation rules
    1)rule which checks the length of rule input (not more than 20 inputs )
    2)one more rule which checks the duplicate in rule input array using contains function
  • Hi kchaitanyam  I have changed my rule input to array now. But the problem is on the interface. How should i take the user input for PR field. Earlier i was using a!IntegerField() but i can not use it now because if there are 2 PR nos then user will enter both numbers using comma(,) as separator.

    a!integerField(
          label: "PR",
          labelPosition: "ABOVE",
          value: ri!PRnumber,
          saveinto: ri!PRnumber,
          refreshAfter: "UNFOCUS",
          validations: {
        if(
          isnull(ri!PRnumber),
          {},
          if(
            length(rule!CheckPRNumber(ri!PRnumber)) = 0,
            "PR Number does not exist.",
            {}
          )
        )

     

    What changes should i do to make it work ? Also please help me with creating the other expression rule to detect duplicate numbers if possible.

  • +1
    A Score Level 2
    in reply to prais1852

    The below code might help you, I didn't concentrated the validation part when user enters other than number you can validate when user enters other than numbers in the text field. let me know if you face any issue.

    note: I took the rule input as Integer array type you can try with text also.

    rule!getPNData(PN:{local!list})/* please replace here with your query entity rule this rule input need to take list*/

    =load(
    local!list,
    local!dBlist,
    local!notInDB,
    a!sectionLayout(
    label: "Lorem Ipsum",
    firstColumnContents: {
    a!textField(
    label: "Lorem Ipsum",
    labelPosition: "ABOVE",
    value:ri!task,
    saveInto: {ri!task,
    if(
    rule!APN_isBlank(ri!task),
    {},
    {
    a!save(
    local!list,fn!split(ri!task,",")
    ),
    a!save(local!list,tointeger(local!list)),
    a!save(local!dBlist,
    rule!getPNData(PN:{local!list})/* please replace here with your query entity rule this rule input need to take list*/

    ),
    a!save(local!dBlist,tointeger(local!dBlist)),
    a!save(local!notInDB,difference(local!list,local!dBlist))
    }
    ),

    },
    refreshAfter: "UNFOCUS",
    validations: {
    if(rule!APN_isBlank(local!notInDB),"","Cannot able to fetch data for "&local!notInDB)
    }
    ),
    a!textField(
    label:"DB Data",
    value:local!dBlist
    )
    },
    secondColumnContents: {
    /* Add components here for a two-column section */
    },
    validations: {}
    )
    )