Hi Krish,
Yes, you are right. One thing I would add that as you mentioned in step 4 the master Agreement list would have only one MA with the given object id, as in master data with the same object id we cannot find more than one MA.
Integer masterAgr= doc.getObjectReference().getObjectId() would return you the object id of current doc you are running script for.
You can use alternate methods as well;
ContractIBeanHomeIfc maHome= IBeanHomeLocator.lookup(session, ContractIBeanHomeIfc.sHOME_NAME);
ContractIBeanIfc ma1=(ContractIBeanIfc) maHome.find(doc.getObjectReference());
ContractIBeanIfc ma2=(ContractIBeanIfc) maHome.findByUniqueDocName(doc.getDisplayName());
ContractIBeanIfc ma3= (ContractIBeanIfc) maHome.findForEdit(doc.getObjectReference());//you can edit the MA using this method.
Hope this would solve your issue,
Regards,
Kumud