How to write script for agent to search document and edit targetted document?

I am really sorry, I am still learning lotus script. I wonder has anyone written any formula on the following scenario:

Agent will run through a view, to check the field category, if category is “allocated cost”, it will refresh the document, other wise, it will run through the view, and stop at the end of the document. It will not be run at category level, but only at document level.

Currently, I will need to change view selection, or select document manually.

Any help is greatly appreciated.