Skip to main content
Version: v6.5.0

Search for departments by name

Command Description

Search for relevant departments based on their names (names must match exactly). Return department IDs in array format

Command Prototype

DepartmentIdArray = WxWork.FindDepartment(wxwork_obj, department_name, parent_id)

Command parameter

parametermandatorytypedefault valueInstructions
wxwork_objTrueexpressionWxWorkObjectEnterprise WeChat object created using the WxWork. Create command
department_nameTruestringFinance DepartmentThe name of the department to be searched can be one department or multiple departments. If there are multiple departments, please use an array to represent them, where each element in the array is a department to be searched for
parent_idTruestring""Specify a department ID to search for all subordinate departments (including subordinate departments of subordinate departments) within this department. If specified as empty or empty string, search for all departments in the entire enterprise

Return result

Return_array, Assign the result of running the command to this variable.

Run instance

/********************************* Find Department by Name ************************************
Command Prototype:
DepartmentIdArray = WxWork.FindDepartment(wxwork_obj, department_name, parent_id)
Input Parameters:
wxwork_obj -- WeChat Work object. Note: WeChat Work object created using the WxWork.Create command.
department_name -- Department name. Note: The name of the department(s) to search for. Can be a single department or multiple departments. If multiple departments, represent as an array where each element is a department to search for.
parent_id -- Parent department. Note: Specify a department ID to search within all subordinate departments (including sub-subordinate departments) of this department. If specified as empty or empty string, searches across all departments in the entire enterprise.
Output Parameters:
return_array -- Variable to store the output of the function call.
Important Notes:
None
********************************************************************************/
Dim return_array = ""
DepartmentIdArray = WxWork.FindDepartment(WxWorkObject, "财务部", "")
TracePrint(return_array)