If there is same Component X in two different menus, menu1 and menu2 and if u want to assign a different search record for each menu, then which peoplecode function do u use and where do u write the code?

In menu item properties (i.e where u tie the component to the menu), there u have an option to override the present component. specify the new component name that u want to attach for that menu.