convert a!query to value to be saved

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)
          ),

  Discussion posts and replies are publicly visible

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

  •   a!forEach(
                items:rule!KONE_Development_Username_UserId(),
                expression:if(fv!item.NAME=ri!userinputsheet.KONE_user_name,
                a!save(target:ri!userrole.USER_ID,value:fv!item.USER_ID),{}
                )
              ),
              
              
    rule as:
     a!queryEntity(
       entity: cons!KONE_Development_userrole_Constant,
       query: a!query(
         pagingInfo: a!pagingInfo(
           startIndex: 1,
           batchSize: 50,
         ),         
         aggregation:a!queryAggregation(
           aggregationcolumns:{
             a!queryAggregationColumn(field:"NAME",alias:"username",isGrouping:true),
             a!queryAggregationColumn(field:"USER_ID",alias:"userid",isGrouping:true),
           }
         )
       ),
     ).data
    

    But not working either.

Reply
  •   a!forEach(
                items:rule!KONE_Development_Username_UserId(),
                expression:if(fv!item.NAME=ri!userinputsheet.KONE_user_name,
                a!save(target:ri!userrole.USER_ID,value:fv!item.USER_ID),{}
                )
              ),
              
              
    rule as:
     a!queryEntity(
       entity: cons!KONE_Development_userrole_Constant,
       query: a!query(
         pagingInfo: a!pagingInfo(
           startIndex: 1,
           batchSize: 50,
         ),         
         aggregation:a!queryAggregation(
           aggregationcolumns:{
             a!queryAggregationColumn(field:"NAME",alias:"username",isGrouping:true),
             a!queryAggregationColumn(field:"USER_ID",alias:"userid",isGrouping:true),
           }
         )
       ),
     ).data
    

    But not working either.

Children
No Data