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
  • 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.

Children
  • +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: {}
    )
    )

  • I would suggest to go for an approach involving Stored Procedure.

    The field which you want to validate pass that to the SP as parameter, run the query to check IF EXISTS in the table.
    Set a out parameter if you find the match and pass it back to the process and route the user back to the UI where it shows the error message based on the out parameter (this is on assumption you want to validate the PR No. and need to show the message on UI if it already exists).

    This will improve performance and will be quick and you wont end up with the error message for 1MB.

    Thanks
  • Hi I like your approach but i am getting problem with my expression rule. How can i modify my expression rule to store values in the same way you are doing using split() method. For all the PR numbers i am getting mismatch on using expression rule with a!queryEntity(). However when i am using Query Rule that problem is not coming but i can't use Query Rule to show exactly which PR number doesn't exist. I like your approach but finding it difficult to debug the error.
  • Hi I like your approach but i am getting problem with my expression rule. How can i modify my expression rule to store values in the same way you are doing using split() method. For all the PR numbers i am getting mismatch on using expression rule with a!queryEntity(). However when i am using Query Rule that problem is not coming but i can't use Query Rule to show exactly which PR number doesn't exist. I like your approach but finding it difficult to debug the error.
  • Hi The way expression rule is returning the values and you are formatting the user input to validate PR numbers are not matching. Result of which i am getting false value only. How can i modify my expression rule in the same format as your are formatting the input data using split() and then match for validation ?
  • Which component we are providing for multiple selection.