I haven't tried anything because I don't even know where to start.
Googl'ing for answers, I came across functions like getgrnam but they
give a list of users in a group. I want it the other way round. Given
a user id, how to determine the groups?
You mean: you don't know anything about Perl? Or you don't know anything
about where Solaris keeps this information?
One of the major features of Perl are its text processing abilities.
Usually Un*x base systems keep the information about users and groups in
text files in /etc (I would be surprised if Solaris did otherwise).
So, adding 1(text processing features) and 1(information kept in text
files) together should get you started. If you have problems getting the
first line of Perl code into the machine or onto a sheet of paper, this
group is definitely the wrong place to start. Better get a decent book,
e.g. the camel book, and start reading.
You wrote "I'm working os a script ...", so you must at least have
something to start with.
Eeven if you post a rudimentary program that shows that you at least
tried to do some work yourself, you'll find legions of people willing to
help (well, maybe not legions).
This is not a group to ask for ready-to-use solutions.