Interface to retrieve record

Hi, I am tasked to do a timesheet POC,

I am asking the user to select the date, and I will using the weeknum function to find out the week number,

after that will add into the database and wait for supervisor approval. 

How to verify the week number is exist in the database record before the user submits the form. 

Please kindly assist me thank you 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    add validation to the week number field by querying the data from data base and check if the entered week number exist in that , based on conditions you can add validations or please elaborate more.  

  • you mean do the validation on the week Number field, I have write an expression rule to retrieve the record from database filter via when the weekNum = ri!weekNum.

    but I don't know how to call the rule at interface and checking the weeknum based on the user input. 

  • 0
    Certified Associate Developer
    in reply to Sunny Yong

    here is the code for adding validation

    {
      a!dateField(
        label: "Date",
        labelPosition: "ABOVE",
        value: ri!date,
        saveInto: {ri!date},
        validations: {if(ri!date>today(),{},"enter a valid date")}
        //if ou have a rule for deciding then
        // validations : if(rule!yourRule(ri!date),{},"not a valid week"
      )
    }

    it will restrict the user from submiting the form untill that field is valid , plus you have to validate the submit button.

  • I need to check my database for the previous record, if the week num exists in the database, will not allow the user to add the same week num of data into the database.

    how to do it?

    a!queryEntity(
      entity: cons!TS_TIMESHEET_DS_POINTER,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "workweek",
              operator: "=",
              value: ri!weekNum
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: true
    ).data

  • +1
    Certified Associate Developer
    in reply to Sunny Yong

    try this, if this returns true then value exists otherwise it doesn't exist in the data base 

    contains(a!queryEntity(
      entity: cons!TS_TIMESHEET_DS_POINTER,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "workweek",
              operator: "=",
              value: ri!weekNum
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: true
    ).data."workweek",ri!weekNum)

Reply
  • +1
    Certified Associate Developer
    in reply to Sunny Yong

    try this, if this returns true then value exists otherwise it doesn't exist in the data base 

    contains(a!queryEntity(
      entity: cons!TS_TIMESHEET_DS_POINTER,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "workweek",
              operator: "=",
              value: ri!weekNum
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: true
    ).data."workweek",ri!weekNum)

Children