# classname_autoid_find

> This function returns a handle to the object referenced by its autoid.

### Prototype

>         MCO_RET	classname_autoid_find(	/*IN*/ mco_trans_h trans,
>                             /*IN*/ autoid_t id
>                            /*OUT*/ classname * handle );

### Arguments

trans | A `MCO_READ_WRITE` transaction handle returned by`mco_trans_start()`
id | The autoid value of the object to be located
handle | The address of a variable of type ``class handle``

### Description

This function will return a handle to the object referenced by the autoid value in the argument `id`.

### Return Codes

MCO_S_OK | The object was located successfully
MCO_S_NOTFOUND | There are no objects referenced by the autoid value given
MCO_E_TRANSACT | Transaction is in an error state

### Example

> The following code snippets demonstrate how `classname_autoid_find()` is used to lookup a database object.

>         Snippet from schema file:

>         class Department
>         {
>             autoid[1000];
>             string name;
>             string code;

>             unique tree<name> Iname;
>             unique tree<code> Icode;
>         };

>         class Employee
>         {
>             string name;
>             autoid_t dept;

>             unique tree<name> Iname;
>             unique tree<dept,name> Idept_name;
>         };

>         Application snippet:

>         MCO_RET find_coworkers(mco_db_h db, char * search_name)
>         {
>             MCO_RET rc = MCO_S_OK;
>             mco_trans_h t;
>             Employee emp;
>             autoid_t dept_id1;
>             Department dept1;

>             /* Find co-workers of search_name */
>             rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);

>             ...

>             // 1. find employee record by name
>             rc = Employee_Iname_find(t, search_name, (uint2)strlen(search_name), &emp);
>             if (MCO_S_OK == rc)
>             {
>                 printf("\n\n%s's co-workers in ", search_name);
>                 Employee_dept_get(&emp, &dept_id1);

>                 // 2. Find the Department object by its autoid
>                 rc = Department_autoid_find(t, dept_id1, &dept1);

>                 ...
>             }
>         }

Related Topics