Skip to Content
0
Former Member
Apr 11, 2012 at 07:30 AM

Workflow prescript errors finding the document owner and using compareTo

25 Views

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

  1. 1) I am getting a parse error on the compareTo line of the code. Do I need to convert one of these numbers so that I am comparing the same type of data?
  2. doc.getOwnerObjRef() is not picking up the owner of the document, should I be using different code to find the owner user account and get my extension field from it?

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);

}

}