One to Many Relationship - update record

Certified Senior Developer

Hi all,

I have two records: Employees and Managers.

Each manager has multiple employees (One to many relationship)

Manager table is like this:

ID NAME LAST NAME

Employees table is like this:

ID Manager ID Name Last Name

When I'm updating the Manager record I want to be able to edit that manager Id of the employees table, since sometimes some employees might change manager or might not have a manager at all. So first , I'm trying that when the user is updating the manager record when they  click on a dynamic link(icon) on the name of the employees under that specific  manager, they can set that to NULL, so basically make that employee no longer have that manager. What is the best way to reference this if I'm using a rule input of type manager in my interface.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    a!localVariables(
      local!result,
      local!managerEmployees: a!refreshVariable(
        value: cast(
          'recordType!{}T Manager',
          a!queryRecordType(
            recordType: 'recordType!{}T Manager',
            fields: {
              'recordType!{}T Manager.relationships.{}tEmployee'
            },
            filters: {
              a!queryFilter(
                field: 'recordType!{}T Manager.fields.{}id',
                operator: "=",
                value: ri!manager['recordType!{}T Manager.fields.{}id']
              )
            },
            pagingInfo: a!pagingInfo(1, 1)
          ).data
        ),
        refreshOnVarChange: local!result
      ),
      {
        a!richTextDisplayField(
          value: a!richTextItem(text: "My Employees", style: "STRONG")
        ),
        a!forEach(
          items: local!managerEmployees['recordType!{}T Manager.relationships.{}tEmployee'],
          expression: a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                width: "AUTO",
                item: a!richTextDisplayField(
                  value: a!richTextItem(
                    text: fv!item['recordType!{}T Employee.fields.{}name']
                  )
                )
              ),
              a!sideBySideItem(
                width: "MINIMIZE",
                item: a!richTextDisplayField(
                  value: a!richTextItem(
                    text: "Remove manager",
                    link: a!dynamicLink(
                      saveInto: {
                        a!writeRecords(
                          records: a!update(
                            fv!item,
                            'recordType!{}T Employee.fields.{}managerId',
                            null
                          ),
                          onSuccess: a!save(local!result, now())
                        )
                      }
                    )
                  )
                )
              )
            }
          )
        )
      }
    )

Reply
  • 0
    Certified Lead Developer

    a!localVariables(
      local!result,
      local!managerEmployees: a!refreshVariable(
        value: cast(
          'recordType!{}T Manager',
          a!queryRecordType(
            recordType: 'recordType!{}T Manager',
            fields: {
              'recordType!{}T Manager.relationships.{}tEmployee'
            },
            filters: {
              a!queryFilter(
                field: 'recordType!{}T Manager.fields.{}id',
                operator: "=",
                value: ri!manager['recordType!{}T Manager.fields.{}id']
              )
            },
            pagingInfo: a!pagingInfo(1, 1)
          ).data
        ),
        refreshOnVarChange: local!result
      ),
      {
        a!richTextDisplayField(
          value: a!richTextItem(text: "My Employees", style: "STRONG")
        ),
        a!forEach(
          items: local!managerEmployees['recordType!{}T Manager.relationships.{}tEmployee'],
          expression: a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                width: "AUTO",
                item: a!richTextDisplayField(
                  value: a!richTextItem(
                    text: fv!item['recordType!{}T Employee.fields.{}name']
                  )
                )
              ),
              a!sideBySideItem(
                width: "MINIMIZE",
                item: a!richTextDisplayField(
                  value: a!richTextItem(
                    text: "Remove manager",
                    link: a!dynamicLink(
                      saveInto: {
                        a!writeRecords(
                          records: a!update(
                            fv!item,
                            'recordType!{}T Employee.fields.{}managerId',
                            null
                          ),
                          onSuccess: a!save(local!result, now())
                        )
                      }
                    )
                  )
                )
              )
            }
          )
        )
      }
    )

Children
No Data