how to use a!writeToDataStoreEntity() write data into two tables simultaneously?

as title, how can i add data to multiple table at same time by using a!writeToDataStoreEntity, give me a example code, thank you

  Discussion posts and replies are publicly visible

Parents
  • HI 

    You can write to one Data base table using a!writeToDataStoreEntity() , where as you can use a!writeToMultipleDataStoreEntities() to write data to multiple data base tables 

    below is an example for the a!writeToMultipleDataStoreEntities()

    a!writeToMultipleDataStoreEntities(
    valuesToStore:{
    a!entityData(
    entity:/* DATA STORE ENTITY*/,
    data:/* DATA THAT NEED TO BE STORED*/
    ),
    a!entityData(
    entity:/* DATA STORE ENTITY*/,
    data:/* DATA THAT NEED TO BE STORED*/
    )
    }
    )

    Else if you are using process model then you can go with the Write to Data Store Entity Smart Service .

    docs.appian.com/.../Write_to_Multiple_Data_Store_Entities_Smart_Service.html

  • Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error [evaluation ID = e8134:373fe] : An error occurred while executing a save: Expression evaluation error: You must specify a variable to save into, such as ri!name << fn!sum. Received: Rule or Function Reference.

  • 0
    Certified Senior Developer
    in reply to immortalvirgil

    can you post your code ?
    I would guess, its an issue how you use that function. posted the right usage of it

  • a!localVariables(
      
      
       
      local!allRole:rule!KONE_Development_ROLE(),
      local!allLanguage:rule!KONE_Development_LANGUAGE(),
      local!allBranch:rule!KONE_Development_BRANCH(),
      local!allRegion:rule!KONE_Development_REGION(),
     
        
    
      a!formLayout(
        contents: {
          a!textField(
            label: "Username",
            value: {ri!userinputsheet.kone_user_name},
            saveInto: {
              a!save(target:ri!userinputsheet.kone_user_name,
                     value:save!value),
              a!save(target:ri!userrole.NAME,
                     value:save!value)
             },
            required: true
          ),
          a!textField(
            label: "firstName",
            value: {ri!userinputsheet.FIRST_NAME},
            saveInto: {ri!userinputsheet.FIRST_NAME},
            required: true
          ),
          a!textField(
            label: "LastName",
            value: {ri!userinputsheet.LAST_NAME},
            saveInto: {ri!userinputsheet.LAST_NAME},
            required: true
          ),
          a!textField(
            label: "Email",
            value: {ri!userinputsheet.Email},
            saveInto: {
              a!save(target:ri!userinputsheet.Email,
                     value:save!value),
              a!save(target:ri!userrole.EMAIL,value:save!value)
            },
            required: true
          ),
          a!dropdownField(
            label:"Role",
            placeholder:"---please fill your Role---",
            choiceLabels:reject(fn!isnull,local!allRole),
            choiceValues:reject(fn!isnull,local!allRole),
            value:ri!userinputsheet.Role,
            saveInto:{
            a!save(target:ri!userinputsheet.Role,value:save!value),
            a!save(
              target:ri!userrole.ROLE_ID,
              value: a!forEach
            (items:rule!KONE_Development_Role_RoleId(),
            expression:if(fv!item.Role=ri!userinputsheet.Role,fv!item.Role_Id,{})        
            )),
            a!save(target:ri!userrole.PHASE_ID,
            value:a!forEach
            (items:rule!KONE_Development_Role_RoleId(),
            expression:if(fv!item.Role=ri!userinputsheet.Role,fv!item.Role_Id,{})        
            ))
            },
            required:true       
          ),
          a!dropdownField(
            label:"Branch",
            placeholder:"---please fill your Branch---",
            choiceLabels:reject(fn!isnull,local!allBranch),
            choiceValues:reject(fn!isnull,local!allBranch),
            value:ri!userinputsheet.Branch,
            saveInto:{
            a!save(target:ri!userinputsheet.Branch,value:save!value),
            a!save(target:ri!userrole.BRANCH,value:save!value),
            a!save(target:ri!userrole.BRANCH_ID,
            value:a!forEach
            (items:rule!KONE_Development_Branch_BranchId(),
            expression:if(fv!item.Branch=ri!userinputsheet.Branch,fv!item.Branch_Id,{})        
            ))
            },
            required:true       
          ),
          a!dropdownField(
            label:"Region",
            placeholder:"---please fill your Region---",
            choiceLabels:reject(fn!isnull,local!allRegion),
            choiceValues:reject(fn!isnull,local!allRegion),
            value:ri!userinputsheet.Region,
            saveInto:{
            a!save(target:ri!userinputsheet.Region,value:save!value),
            a!save(target:ri!userrole.REGION,value:save!value),
            a!save(target:ri!userrole.REGION_ID,
            value:a!forEach
            (items:rule!KONE_Development_Region_RegionId(),
            expression:if(fv!item.Region=ri!userinputsheet.Region,fv!item.Region_Id,{})        
            ))
            },
            required:true       
          ),
          a!dropdownField(
            label:"Manager_Role",
            placeholder:"---please fill your Role---",
            choiceLabels:reject(fn!isnull,local!allRole),
            choiceValues:reject(fn!isnull,local!allRole),
            value:ri!userinputsheet.Manager_role,
            saveInto:{
              a!save(target:ri!userinputsheet.Manager_role,value:save!value)
            },
            required:true     
          ),
          a!dropdownField(
            label:"Language",
            placeholder:"---please fill your Language---",
            choiceLabels:reject(fn!isnull,local!allLanguage),
            choiceValues:reject(fn!isnull,local!allLanguage),
            value:ri!userinputsheet.Language,
            saveInto:{
            a!save(target:ri!userinputsheet.Language,value:save!value),
            a!save(target:ri!userrole.LANG_ID,
            value:a!forEach
            (items:rule!KONE_Development_Language_LanguageId(),
            expression:if(fv!item.Language=ri!userinputsheet.Language,fv!item.Language_Id,{})        
            ))
            },
            required:true       
          ),
          a!textField(
            label: "CELevel",
            value: {ri!userinputsheet.CE_LEVEL},
            saveInto: {
              a!save(target:ri!userinputsheet.CE_LEVEL,value:save!value),
              a!save(target:ri!userrole.LEVEL,value:save!value)
            },
            required: true
          ),
          a!textField(
            label: "Telephone Number",
            value: {ri!userinputsheet.Telephone_number},
            saveInto: {
              a!save(target:ri!userinputsheet.Telephone_number,value:save!value),
              a!save(target:ri!userrole.TELEPHONE_NUMBER,value:save!value)
            },
            required: true
          ),
          a!textField(
            label: "Exceptional Case Library View Right",
            value: {ri!userinputsheet.Exceptional_case_library_view_right},
            saveInto: {
              a!save(target:ri!userinputsheet.Exceptional_case_library_view_right,value:save!value),
              a!save(target:ri!userrole.IS_EXCEPTION,value:0),
              a!save(target:ri!userrole.ACTIVE,value:1)
            },
            required: true
          ),    
          },
          buttons:a!buttonLayout(
            primaryButtons:{
              a!buttonWidget(
                label: "Submit",
                saveInto:{
                  a!writeToMultipleDataStoreEntities(
                    a!entityData(entity: cons!KONE_Development_userrole_Constant, data: ri!userrole),
                    a!entityData(entity: cons!KONE_Development_userinputsheet_Constant, data: ri!userinputsheet),
                  ),
                },
                submit: true,
                style: "PRIMARY"
              ),
             
            }
          )
        )
      )
    

    Did I miss any steps?

  • 0
    Certified Lead Developer
    in reply to immortalvirgil

    Hi, I think you are missing the {} in writeToMultipleDataStoreEntities function. Could you please try below code snippet.

    a!buttonLayout(
          primaryButtons:{
            a!buttonWidget(
              label: "Submit",
              saveInto: {
                a!writeToMultipleDataStoreEntities(
                  valuesToStore: {
                    a!entityData(
                      entity: cons!KONE_Development_userrole_Constant,
                      data: ri!userrole
                    ),
                    a!entityData(
                      entity: cons!KONE_Development_userinputsheet_Constant,
                      data: ri!userinputsheet
                    )
                  }
                )
    
              },
              submit: true,
              style: "PRIMARY"
            ),
    
          }
        )

  • you way i tried before, but it report with:

    Interface Definition: Expression evaluation error: An error occurred while executing a smart service: The list of EntityData passed to the smart service contains entities from different data stores. All entities must belong to the same data store. No values have been written. (APNX-1-4208-001)

Reply Children