I want dynamic id instead of static mesh id

I have a mug in which I have applied multiple materials but I want my texture to be applied on a specific material how is it possible

You can assign an ID to your materials, the same way you do with a mesh.
It’s not a unique ID so different materials can have a same ID.
This way you can assign a texture to any material with this ID.
Would that cover your needs?