how can i transfer property 'user' of type Text into type List of Variant

if(isnull(or(ri!a,ri!b)),{},a!forEach(
  items:rule!KONE_Development_CSE_TENDER_PHASES_Search_Rule(ri!a),
  expression:a!localVariables(
    local!csetenderphases:fv!item,
    a!forEach(
      items:rule!KONE_Development_CSE_TENDER_Search_Rule(local!csetenderphases.tenderId),
      expression:
      if(local!csetenderphases.tenderId=fv!item.id,
      if(or(fv!item.statusId="3",fv!item.statusId="4"),{},{
        a!update(data:local!csetenderphases,index:"user",value:ri!b)
      })
      ,{})
    )
  )
).list.user
)

As title, i need transfer all value to be correct form to be saved

thank you all

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    What do you actually want to achieve?

    What did you try? What was the outcome? What is wrong with it?

    The community is not able to help without more details. I try to convince you of this in almost all my replies.

  • hey sir, how are you today, hope you have a nice day.

    The top code is the list i extract from want to save into database put into the value:   and in the rule it return with:

    However, it always report cannot index {'id',"name",...etc} into list of variant, I doubt I couldn't transfer each of columns into the correct data forms put into value:. How can I transfer? I want to save all list of those value return save into database by using a!writeintodatastoreentity.

  • 0
    Certified Lead Developer
    in reply to immortalvirgil

    I can see that you trapped into a typical problem using foreach. The issue here is that you have nested lists. Give a!flatten() a try.

  • It do transform to dictionary and can transform to data, but it is still report the same error Invalid index: Cannot index property 'id' of type Text into type List of Variant. I doubt it can't save a list into database together. How you can do it? thanks 

  • 0
    Certified Lead Developer
    in reply to immortalvirgil

    Here we go again. Do you really want me to spend my time trying to guess what you want to achieve, what you tried and what goes wrong?

    The only spot in your code where that could happen is here

    if(local!csetenderphases.tenderId=fv!item.id,

    So there is a situation in which the item does not have a field "id". I do not know why that happens, but you might want to check the output of 

    rule!KONE_Development_CSE_TENDER_Search_Rule(local!csetenderphases.tenderId)

  • a!localVariables(
      local!searchDeleteUserRole,
      local!tenderValid,
      local!priceValid,
      local!csetenderphaseslist1,
      local!newUser,
      local!csetenderphaseslist:
      a!forEach(
        items:rule!KONE_Development_CSE_TENDER_PHASES_Search_Rule(local!searchDeleteUserRole),
        expression:a!localVariables(
          local!csetenderphases:fv!item,
          a!forEach(
            items:rule!KONE_Development_CSE_TENDER_Search_Rule(local!csetenderphases.tenderId),
            expression:
            if(local!csetenderphases.tenderId=fv!item.id,
            if(or(fv!item.statusId="3",fv!item.statusId="4"),{},{
              a!update(data:local!csetenderphases,index:"user",value:local!newUser)
            })
            ,{})
          )
        )
      ) ,
      local!serviceValid,
      local!userrole:a!refreshVariable(value:rule!KONE_Development_userrole_All()),
      {
      a!sectionLayout(
        label: "Delete User System",
        contents: {
          a!textField(
            label: "USERNAME",
            labelPosition: "ABOVE",
            value:local!searchDeleteUserRole,
            saveInto: {local!searchDeleteUserRole
            },
            refreshAfter: "KEYPRESS",
            validations: {}
          ),
          a!buttonArrayLayout(
            buttons: {
              a!buttonWidget(
                label: "Clear",
                saveInto:a!save(local!searchDeleteUserRole,null()),
                style: "NORMAL"
              )
            },
            align: "START"
          ),
          a!sectionLayout(
            contents: {
              a!columnsLayout(
                columns: {
                  
                  a!columnLayout(
                    contents: {
                      a!gridField(
                        label: "Read-only Grid",
                        labelPosition: "ABOVE",
                        data: a!queryEntity(
                          entity: cons!KONE_Development_userrole_Constant,
                          query: a!query(
                            selection: a!querySelection(
                              columns: {
                                a!queryColumn(field: "USER_ID"),
                                a!queryColumn(field: "NAME"),
                                a!queryColumn(field: "ROLE"),
                                a!queryColumn(field: "BRANCH"),
                                a!queryColumn(field: "REGION")
                              }
                            ),
                            logicalExpression: a!queryLogicalExpression(
                              operator: "AND",
                              filters: {
                                a!queryFilter(
                                  field: "NAME",
                                  operator: "=",
                                  value: local!searchDeleteUserRole
                                )
                              },
                              ignoreFiltersWithEmptyValues: true
                            ),
                            pagingInfo: fv!pagingInfo
                          ),
                          fetchTotalCount: true
                        ),
                        columns: {
                          a!gridColumn(
                            label: "USER_ID",
                            sortField: "USER_ID",
                            value: fv!row.USER_ID
                          ),
                          a!gridColumn(
                            label: "NAME",
                            sortField: "NAME",
                            value: fv!row.NAME
                          ),
                          a!gridColumn(
                            label: "ROLE",
                            sortField: "ROLE",
                            value: fv!row.ROLE
                          ),
                          a!gridColumn(
                            label: "BRANCH",
                            sortField: "BRANCH",
                            value: fv!row.BRANCH
                          ),
                          a!gridColumn(
                            label: "REGION",
                            sortField: "REGION",
                            value: fv!row.REGION
                          )
                        },
                        pagesize: 5,
                        initialsorts: a!sortInfo(
                          field: "USER_ID",
                          ascending: true
                        )
                        
                      )
                    }
                  )
                }
              )
            }
          )
          
        }
      ),
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "",
                  labelPosition: "COLLAPSED",
                  value:"This person has unfullfilled Objectives",
                  saveInto: {},
                  refreshAfter: "UNFOCUS",
                  readonly:true(),
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Please fill in succeed assignee(Manadatory Before Delete)",
                  labelPosition: "ABOVE",
                  value:local!newUser,
                  saveInto: {local!newUser,
                  a!save(target:local!csetenderphaseslist1,value:if(or(isnull(local!searchDeleteUserRole),isnull(local!newUser)),{},
                  a!forEach(
                    items:rule!KONE_Development_CSE_TENDER_PHASES_Search_Rule(local!searchDeleteUserRole),
                    expression:a!localVariables(
                      local!csetenderphases:fv!item,
                      a!forEach(
                        items:rule!KONE_Development_CSE_TENDER_Search_Rule(local!csetenderphases.tenderId),
                        expression:
                        if(isnull(fv!item),
                        {
                        }
                        ,{local!csetenderphases,})
                      )
                    )
                  ),)),
                  },
                  refreshAfter:"KEYPRESS",
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!buttonArrayLayout(
                  buttons: {
                    a!buttonWidget(
                      label: "update",
                      icon: "arrow-circle-up",
                      saveInto:{
                        a!save(target:ri!csetenderphases.id,value:local!csetenderphaseslist.id),
                        a!save(target:ri!csetenderphases.tenderId,value:local!csetenderphaseslist.tenderId),
                        a!save(target:ri!csetenderphases.phaseId,value:local!csetenderphaseslist.phaseId),
                        a!save(target:ri!csetenderphases.lastPhaseId,value:local!csetenderphaseslist.lastPhaseId),
                        a!save(target:ri!csetenderphases.user,value:local!csetenderphaseslist.user),
                        a!save(target:ri!csetenderphases.startDate,value:local!csetenderphaseslist.startDate),
                        a!save(target:ri!csetenderphases.completionDate,value:local!csetenderphaseslist.completionDate),
                        a!save(target:ri!csetenderphases.phaseActive,value:local!csetenderphaseslist.phaseActive),
                        a!save(target:ri!csetenderphases.isPoolTask,value:local!csetenderphaseslist.isPoolTask),
                        a!save(target:ri!csetenderphases.active,value:local!csetenderphaseslist.active),
                        a!save(target:ri!csetenderphases.isActionPerformed,value:local!csetenderphaseslist.isActionPerformed),
                        a!writeToMultipleDataStoreEntities(
                          valuesToStore:{
                            a!entityData(entity:cons!KONE_Development_CSE_TENDER_PHASES_Constant,data:ri!csetenderphases),
                          }
                        ),
                      },
                      disabled:if(or(isnull(local!searchDeleteUserRole),isnull(local!newUser)),true,false),
                      style: "DESTRUCTIVE"
                    )
                  },
                  align: "START"
                )
              }
            )
          },
          showWhen:true
        ),
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "",
                  labelPosition: "COLLAPSED",
                  value:"This person can be delete through procedure",
                  saveInto: {},
                  refreshAfter: "UNFOCUS",
                  showWhen:true(),
                  readonly:true(),
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!buttonArrayLayout(
                  buttons: {
                    a!buttonWidget(
                      label: "SAVE INTO BACK UP",
                      saveInto:{
                        if(isnull(or(local!searchDeleteUserRole,local!newUser)),{},
                        a!forEach(
                          items:local!userrole,
                          expression:
                          if(local!searchDeleteUserRole=fv!item.NAME,
                          {
                          a!save(target:ri!userrolebackup.userId,value:fv!item.USER_ID),
                          a!save(target:ri!userrolebackup.name,value:fv!item.NAME),
                          a!save(target:ri!userrolebackup.email,value:fv!item.EMAIL),
                          a!save(target:ri!userrolebackup.role,value:fv!item.ROLE),
                          a!save(target:ri!userrolebackup.roleId,value:fv!item.ROLE_ID),
                          a!save(target:ri!userrolebackup.branch,value:fv!item.BRANCH),
                          a!save(target:ri!userrolebackup.phaseId,value:fv!item.PHASE_ID),
                          a!save(target:ri!userrolebackup.branchId,value:fv!item.BRANCH_ID),
                          a!save(target:ri!userrolebackup.isException,value:fv!item.IS_EXCEPTION),
                          a!save(target:ri!userrolebackup.region,value:fv!item.REGION),
                          a!save(target:ri!userrolebackup.regionId,value:fv!item.REGION_ID),
                          a!save(target:ri!userrolebackup.area,value:fv!item.AREA),
                          a!save(target:ri!userrolebackup.areaId,value:fv!item.AREA_ID),
                          a!save(target:ri!userrolebackup.managerRole,value:fv!item.MANAGER_ROLE),
                          a!save(target:ri!userrolebackup.langId,value:fv!item.LANG_ID),
                          a!save(target:ri!userrolebackup.active,value:fv!item.ACTIVE),
                          a!save(target:ri!userrolebackup.level,value:fv!item.LEVEL),
                          a!save(target:ri!userrolebackup.telephoneNumber,value:fv!item.TELEPHONE_NUMBER),
                          a!save(target:ri!userrolebackup.superUser,value:fv!item.SUPER_USER),
                          a!save(target:ri!userrolebackup.unit,value:fv!item.UNIT),
                          a!save(target:ri!userrolebackup.unitId,value:fv!item.UNIT_ID),
                          a!save(target:ri!userrolebackup.delegate,value:fv!item.DELEGATE),
                          a!save(target:ri!userrolebackup.delegateforcse,value:fv!item.DELEGATEFORCSE),
                          a!save(target:ri!userrolebackup.subUnit,value:fv!item.SUB_UNIT),
                          a!save(target:ri!userrolebackup.subUnitId,value:fv!item.SUB_UNIT_ID),
                          a!save(target:ri!userinputsheet.KONE_user_name,value:fv!item.NAME),
                          a!save(target:ri!userinputsheet.updateTime,value:now()),
                          a!save(target:ri!userinputsheet.reason,value:"Delete"),
                          a!writeToMultipleDataStoreEntities(
                            valuesToStore:{
                              a!entityData(entity:cons!KONE_Development_BACKUP_USER_ROLE_Constant,data:ri!userrolebackup),
                              a!entityData(entity:cons!KONE_Development_BACKUP_USER_AUDIT_Constant,data:ri!userinputsheet)
                            }
                          )
                          }
                          ,{})
                        )
                        )
                      },
                      style: "PRIMARY",
                      disabled:if(isnull(local!searchDeleteUserRole),true(),if(length(rule!KONE_Development_BACKUP_USER_ROLE_exist_Rule(local!searchDeleteUserRole))=0,false(),true()))
                    )
                  },
                  align: "START"
                ),
                a!textField(
                  label: "",
                  labelPosition: "COLLAPSED",
                  value:{"Saved to back up successfully"},
                  refreshAfter: "UNFOCUS",
                  showWhen:if(isnull(local!searchDeleteUserRole),false(),if(length(rule!KONE_Development_BACKUP_USER_ROLE_exist_Rule(local!searchDeleteUserRole))=0,false(),true())),
                  readonly:true,
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!buttonArrayLayout(
                  buttons: {
                    a!buttonWidget(
                      label: "Delete",
                      saveInto:{
                        a!forEach(
                          items:local!userrole,
                          expression:
                          if(fv!item.NAME=local!searchDeleteUserRole,{
                            a!deleteFromDataStoreEntities(
                              dataToDelete: {
                                a!entityDataIdentifiers(
                                  entity: cons!KONE_Development_userrole_Constant,
                                  identifiers:{fv!item.USER_ID}
                                )
                              }
                            )
                          },{})
                        )
                      },
                      style: "PRIMARY",
                      disabled:if(isnull(local!searchDeleteUserRole),true(),if(length(rule!KONE_Development_BACKUP_USER_ROLE_exist_Rule(local!searchDeleteUserRole))=0,true(),if(length(rule!KONE_Development_userroleexist_Rule(local!searchDeleteUserRole))=0,true(),false())))
                    )
                  },
                  align: "START"
                ),
                a!textField(
                  label: "",
                  labelPosition: "ABOVE",
                  value:"Deleted successfully",
                  saveInto: {},
                  refreshAfter: "UNFOCUS",
                  showWhen:if(isnull(local!searchDeleteUserRole),false(),if(length(rule!KONE_Development_BACKUP_USER_ROLE_exist_Rule(local!searchDeleteUserRole))=0,false(),if(length(rule!KONE_Development_userroleexist_Rule(local!searchDeleteUserRole))=0,true(),false()))),
                  readonly:true
                )
              }
            )
          }
        )
    })
    errors from line 178, I am doing update system form certain users leave the system, after it left, we going to check its tenderId from table KONE_Development_CSE_TENDER_PHASE_CDT, inner join the ID from table

    KONE_Development_CSE_TENDER_CDT by a.tenderId=b.Id, if the second table statusId not equal to 3 or 4(which mean such assignment not finished), we going to assign new person which local!newUser fill in the text blank left of button "update".

  • 0
    Certified Lead Developer
    in reply to immortalvirgil

    I can not follow anymore ... are we talking about a attribute "user" as in the headline, about a missing field "id" as in my last post, or about the code in your initial post?

  • if it validate that this tenderId != 3 or 4 then we going to assign it a another use which is local!newuser

  • Yes, I mean any attribute i wish to insert report same error,can't index 'user' of type Text into type List of Variant

    or{

    can't index 'user' of type Text into type List of Variant,

    can't index 'id' of type Text into type List of Variant,

    can't index 'tenderId' of type Text into type List of Variant,

    can't index "XXXXX' of type Text into type List of Variant

    }

  • sorry, not being rude, just this size after paste it, so annoying, sorry sir

Reply Children