Skip to main content
September 8, 2021
Question

convert a!query to value to be saved

  • September 8, 2021
  • 11 replies
  • 0 views

seems I almost there, the problem I found is that the value i supposed to be saved for a!query is not the standard form. What should be the correct one?

a!save(target:ri!userrole.USER_ID,
          value:cast(type!Integer,
            a!queryEntity(
              entity:cons!KONE_Development_userrole_Constant,
              fetchTotalCount:true,
              query:a!query(
                selection: a!querySelection(
                  columns: {
                    a!queryColumn(
                      field: "USER_ID"
                    )
                  }
                ),
                filter:a!queryFilter(
                  field:"NAME",operator:"=",
                  value:ri!userinputsheet.kone_user_name,
                  applyWhen:not(isnull(ri!userinputsheet.KONE_user_name))
                ),
                pagingInfo:a!pagingInfo(
                  startIndex: 1,
                  batchSize: 50
                )
              )
            ).data.USER_ID)
          ),

    11 replies

    September 8, 2021

    I think i have to trim the bracket

    marco.amador
    September 8, 2021

    In general I would say you should avoid having a queryEntity inside a saveInto. If the query fails or does not retrieve the results you expect (since you are using a batchSize of 50 for it), you will be saving the wrong values into USER_ID without a good way to debug it.

    September 8, 2021

    i have if judgement if the value is null but i didn't put it in here

    September 8, 2021

    target:ri!userrole.USER_ID,
    value:a!forEach(
    items:rule!KONE_Development_Username_UserId(),
    expression:if(fv!item.username=ri!userinputsheet.KONE_user_name,
    fv!item.userid,{})
    )

    I did both way but neither is work

    mikes0011
    Brainy
    September 8, 2021

    Why are you doing this in this spot, exactly?  And how (and when) does the value of `ri!userinputsheet.kone_user_name` get set?

    The Expression Guru
    September 9, 2021

    what do you mean, I did in the rule input

    mikes0011
    Brainy
    September 9, 2021

    Your query is attempting to look up the user ID of the database entry(s) matching `ri!userinputsheet.kone_user_name`.  I'm trying to discern what your use case is exactly, and that includes how the value of this is initialized.

    The Expression Guru