cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow prescript errors finding the document owner and using compareTo

Former Member
0 Kudos

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

                }

}

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Dan,

In your code, to find the owner, you are doing typeHome.find(doc.getOwnerObjRef()), but typeHome is not defined anywhere. You may want to take a look at that.

Regards,

Vikram

Former Member
0 Kudos

Hi Vikram,

Thank you for your help with this.

I have updated the error in the code, it now ready as:

// Get home and bean

ownerHome = IBeanHomeLocator.lookup(session, doc.getOwnerObjRef());

ownerBean = ownerHome.find(doc.getOwnerObjRef());

// Get the document owner approval limit

ownerapproval = ownerBean.getExtensionField("approvallimit").get()

I am still getting errors on this part of the code. Is the above the correct method for getting the document owner or should I be getting the collaborator collection and looking at the first row?

Many thanks

Dan

0 Kudos

Hi Dan,

To get the owner of the Project, you need to use doc.getDocumentOwnerUserReference()

Vikram

Former Member
0 Kudos

Hi Vikram,

Thank you for your continued help with this. The workflow is now working as intended!

Many thanks

Dan

Answers (0)