Hi All,
I have a requirement for approval prescript to add an approver only if the Project Estimated Value is over an approval limit contained in an extension field on the document owner’s user account.
I have created a decimal extension field on the user account called approvallimit and I have created a group extension field on the Project header called Level1AppGrp.
I have created the below prescript and I am having two problems with it:
Problem
Many thanks
Dan
import com.sap.odp.api.common.exception.*;
import com.sap.odp.api.common.log.Logger;
import com.sap.odp.api.common.platform.*;
import com.sap.odp.api.common.types.*;
import com.sap.odp.api.doc.collaboration.*;
import com.sap.odp.api.ibean.*;
import com.sap.odp.api.util.*;
import com.sap.odp.api.workflow.*;
import com.sap.eso.api.projects.*;
import com.sap.eso.api.doccommon.masterdata.*;
import com.sap.odp.api.doccommon.masterdata.*;
import com.sap.odp.api.common.log.*;
import com.sap.odp.api.usermgmt.masterdata.*;
import com.sap.odp.api.doc.collaboration.*;
import java.math.*;
// These hold the name of the extension fields we are concerned
level1ApproverExtName = "Level1AppGrp";
// Create a logger for messaging
logMsg = Logger.createLogMessage(session);
// Get home and bean
ownerHome = IBeanHomeLocator.lookup(session, doc.getOwnerObjRef());
ownerBean = typeHome.find(doc.getOwnerObjRef());
// Get the document owner approval limit
ownerapproval = ownerBean.getExtensionField("approvallimit").get()
// Compare the estimated value to the document owner approval limit
if (hasValue(ownerapproval) @and
ownerapproval.compareTo(doc.getEstimatedValue().getPrice()) < 0)
{
// Level 1 Approver
principal =doc.getExtensionField(level1ApproverExtName).get();
if (hasValue(principal))
{
// Add the user account as the approver
addApprover(principal,new CollaboratorApprovalRuleType(0));
// log details
logMsg.setLogMessage("Added user: " + principal.getDisplayName() + " as approver");
Logger.info(logMsg);
}
}