How to Sync Employee Lists with Lark AnyCross

0
15

How to Sync an Employee List with Lark AnyCross

Keeping track of who has joined, who has left, and whose account is suspended is a repetitive job that grows with every new hire.

This guide shows how to build a Lark AnyCross workflow that runs every day, pulls your company’s account list from Lark, and writes it into a Lark Sheet, sorted by account status.

The example uses dummy data, so you can follow along safely.

The Scenario

Alex is an HR specialist at a growing company. Every week, and sometimes every day, he checks the onboarding, offboarding, and account status of hundreds of employees by hand.

It is tiring and easy to get wrong. To break out of the cycle, he builds an automated workflow in Lark AnyCross that keeps a master employee list up to date, covering Active, Frozen (suspended), and Unjoin (invited) accounts.

How the Workflow Is Structured

The workflow has three parts:

  1. Start: A daily scheduler, a step that clears the old data from the sheet, and two variables that control pagination.
  2. While loop: Fetches employees from Lark in batches until there are no more.
  3. Loop: For each employee, looks up user and department details, classifies the account status, and appends a row to the sheet.

AnyCross workflow start showing a scheduler, two Lark Sheets steps, two variables and a while loop

Part 1: Start the Workflow

Step 1: Add a Daily Scheduler

In the first node, add a Scheduler and select Trigger on a daily basis. Choose the time you want the workflow to run, and keep the default time zone and effective period.

Scheduler settings in AnyCross with a daily trigger time, time zone and default effective period

Step 2: Get the Spreadsheet Metadata

Add a Lark Sheets node and choose the Obtain Spreadsheet Metadata action. Enter the token of your target sheet in the Sheet token field, enter null for Additional returned fields, and set the User ID type to open_id.

Lark Sheets Obtain Spreadsheet Metadata input with sheet token, additional fields null and open_id user type

Step 3: Clear the Old Data

Add another Lark Sheets node and choose Delete rows or columns. This wipes the previous day’s list so the sheet is rebuilt fresh each time.

  • Link the spreadsheet token to the output of the previous node using the connection icon on the left.
  • Select the target Sheet ID.
  • For Operate on, choose Row.
  • Set Start position to 2, so the header row is kept.
  • Set End position to rowCount from the metadata step, which is the maximum number of rows in the sheet.

Animated setup of the Delete rows action with sheet ID, row selection, start position 2 and rowCount end

Step 4: Create the Pagination Variables

Add a Set variable node named page_token (renaming is optional). Set its data type to String and its value to null, as a placeholder for the pagination marker before any data is retrieved.

Set variable node named page_token with a string data type and null value in AnyCross

Add a second Set variable node named has_more, with the data type Boolean and the value true. This is what keeps the While loop running as long as there are more accounts to pull.

Set variable node named has_more with a boolean data type and a value of true in AnyCross

Part 2: Fetch Employees With a While Loop

Step 5: Add the While Loop

Add a While loop node and link its loop condition to the has_more variable. Set the maximum number of loops to the highest allowed limit. A While loop is needed because the Lark Organization Structure API returns at most 100 records per request, so the request has to repeat until every record has been retrieved.

While loop node with the has_more variable as its loop condition and a maximum of 1000 loops

Step 6: Get the Employee List in Batches

Inside the loop, add the Lark Organizational Structure node and choose the Get employee list in batches action. Then configure it:

  • Identity: Use Open ID for the user ID type and Open Department ID for the department ID type, so identifiers stay consistent throughout the workflow.
  • Status filter: Set work_info.staff_status equal to 1 to filter the employee status.
  • Fields to query: Tick the fields you need, such as name, employee ID, mobile, email, and active status.
  • Pagination: Set the number of requests to 100 and map the pagination marker to your page_token variable, so each round picks up where the last one stopped.

Get employee list in batches settings with ID types, a staff status filter, queried fields and pagination

Step 7: Loop Through the Employees

Add a Loop node and choose Serial loop. In the Loop list under the Input tab, select employees (Employee information) from the previous node’s output.

Step 8: Update the Pagination Variables

After the loop, add two more Set variable nodes inside the While loop. Name one page_token (String) and link it to the page_token output of the Lark Organizational Structure node. Name the other has_more (Boolean) and link it to that node’s has_more output.

Response fields with has_more and page_token from page_response highlighted in the AnyCross data picker

Why set the variables again? Each batch response tells the workflow whether more data remains (has_more) and where the next batch starts (page_token). Saving both at the end of every round lets the While loop continue to the next page. Without updating them, the loop would either stop after the first page or keep fetching the first page forever.

Part 3: Process Each Employee

Optional: You can add a Delay Helper node at the start of this stage if you want to space out requests. Include it or leave it out depending on your needs.

Step 9: Get User Information

Add a Lark Contacts node and choose Obtain bulk user information. Set the User ID category to open_id and the Department ID type to open_department_id, matching your earlier settings. Under User Identification, switch to Array, add an element, and map element 0 to employee_id from the loop node.

Get User Information input with open_id categories and an array element mapped to the loop employee_id

Step 10: Get Department Information

Add another Contacts node and choose Obtain bulk department information. Set the Department ID type to open_department_id and the User ID category to open_id. In the Department IDs field, switch to Array mode, add an element, and map element 0 to department_ids[0] from the Get User Information node. Using the first item rather than the whole list works here because each round only needs one primary department.

Get User Department Information input with open_department_id types and department_ids mapped in element 0

Step 11: Classify Account Status With a Branch

Add a Branch node with five conditions: Frozen, Resigned, Active, Exited, and Unjoin. For Frozen, use the mapping icon to pull is_frozen from the User status group in the Get User Information node, and set the condition to true. Repeat for the other categories. This step exists to classify each account’s status.

Animated branch setup choosing is_frozen from the user status fields for the Frozen condition

Workflow showing a Branch node splitting into Frozen, Resigned, Active, Exited and Unjoin Lark Sheets steps

Step 12: Write Each Employee to the Sheet

On every branch, add a Lark Sheets node and choose Append data. Enter the target spreadsheet token, then in the Insert a range field enter your Sheet ID and column range in the format SheetID!A:G.

Under Values to be written, map elements 0 to 6 in the same order as your sheet columns:

  • open_id, name, job title, email, and mobile come from the Get User Information node.
  • Department name comes from the Get Department Information node.
  • Work Status is typed in manually for each branch (for example, Frozen), because it cannot be pulled as a single value. This is the main reason for using the branch.

Append data values mapping employee fields and a manual Frozen status into an array in Lark Sheets

Tip: Values to be written is a two-level array. The outer level is the list of rows you want to append, and the inner level is the list of cells within each row. One outer element with seven inner elements writes one row of seven columns.

The Result

Each day the workflow clears the sheet and rebuilds it with every account, its department, and its status.

Lark Sheets employee list with Employee ID, Work Status, Name, Department, Job Title, Email and Phone columns

Practical Use Cases for SMEs and Startups

  • Onboarding and offboarding checks: See at a glance who has joined, who is still unjoined, and whose account is frozen.
  • Licence and access reviews: Give IT a daily-refreshed list to check against licences and system access.
  • HR reporting: Feed the sheet into a dashboard for headcount by department and status.
  • Audit preparation: Keep a consistent record of account statuses without manual exports.

Frequently Asked Questions (FAQ)

Why does the workflow need a While loop?

The Lark Organization Structure API returns a maximum of 100 records per request. The While loop repeats the request until there are no more records.

What do the page_token and has_more variables do?

page_token marks where the next batch of data starts, and has_more tells the loop whether there is more data to fetch. Together they keep the loop moving from page to page and stop it at the end.

Why are the two variables updated again at the end of the loop?

Every response carries a new page marker and a new has_more value. Saving them lets the next round fetch the next page. Without this step, the loop would stop after the first page or fetch the first page repeatedly.

Why does the workflow delete the rows before writing new data?

Clearing the sheet from row 2 downward removes yesterday’s list, so the sheet always holds a fresh copy and old entries do not pile up. Row 1, the header, is kept.

Why is a branch needed to write the work status?

The user information does not return the status as a single value. It returns separate true or false flags such as is_frozen, so a branch classifies each account and each branch writes its own status text.

Do I need the Delay Helper node?

No, it is optional. Include it if you want to space out requests, and leave it out if you do not.

An Employee List That Updates Itself

Once the workflow is running, HR no longer needs to check accounts by hand. The list refreshes itself every day, and your team can trust the numbers it sees.

Ready to Power Your Business with Lark?

Lark AnyCross is just one part of an all-in-one platform that brings messaging, meetings, documents, approvals, and automations together for your entire team.

As the Platinum Partner for Lark in Malaysia, Exabytes offers tailored Lark plans, hands-on onboarding, and dedicated local support to help your team automate routine HR tracking.

Explore Lark plans with Exabytes today