cancel
Showing results for 
Search instead for 
Did you mean: 

Issues adding one single approver into a Project worflow

isaac_ariza_cruz
Participant
0 Kudos

Hi all,

I'm new in SAP Sourcing and I'm trying to develop the following requirement:

An extension field has been added to class "Project". This extension field is placed on Project header and it is a value list which contain user ids (same userID than the assigned in the user account data);

- "UserID_1"

- "UserID_2"

- ...

Furthermore, a workflow with only one approval level has been defined (using TWE) and its corresponding pre-script has been defined as follow:

// Add approver from a new Extension Field created at Project Header as Value List:

//---------------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------------

import com.sap.odp.api.common.*;

import com.sap.odp.api.usermgmt.masterdata.*;

import com.sap.odp.api.doc.collaboration.*;

// Create a logger for messaging

logMsg = Logger.createLogMessage(session);

// Retrieve the value from the extension field:

approverExtName = "z_app_project";

principal = doc.getExtensionField(approverExtName).get();

if(hasValue(principal))

{

    // Add the user account as the approver

    addApprover(principal);

    

    // log details

    logMsg.setLogMessage("Added user: " + principal.getDisplayName() + " as approver");

    Logger.info(logMsg);

}

Then, I select one of the user IDs of the value list above detailed and I change the project phase to the one raising the workflow. However, following error is displayed on the Background Task Status (Daemon Alerts):

ApplicationException: This field is required and must have a valid value.

com.sap.odp.api.common.exception.ApplicationException: This field is required and must have a valid value.

AssociatedAttribute=COLLABORATORS - SourceBo=-2147483505:1100:ZAK_PROJECT_20120813_2001 - ValidatingParent=-2147483505:1100:ZAK_PROJECT_20120813_2001 - com.sap.odp.api.common.exception.ApplicationException: At least one of the items below is invalid. Mouse over the highlighted area for more details.
at com.sap.odp.api.common.exception.ChainedExceptionFactory.createApplicationException(ChainedExceptionFactory.java:90)
at com.sap.odp.common.db.PersistentBo.createApplicationException(PersistentBo.java:3246)
at com.sap.odp.doc.collection.GeneralCollnBo.createApplicationException(GeneralCollnBo.java:345)
at com.sap.odp.doc.collection.GeneralCollnBo.createApplicationException(GeneralCollnBo.java:357)
at com.sap.odp.doc.collection.SubCollnBo.validateCollection(SubCollnBo.java:1325)
at com.sap.odp.doc.ContainerBo.execValidate(ContainerBo.java:4152)
at com.sap.odp.doc.BizDocBo.execValidate(BizDocBo.java:2008)
at com.sap.odp.doc.ContainerBo.validate(ContainerBo.java:1397)
at...

I've also tried using the following sentence:

// Add the user account as the approver

    addApprover(principal, new CollaboratorApprovalRuleType(0));


... but same error was raised.

Could you kindly please have a look on it and let me know what I'm doing wrong?

I've also check SAP documentation and I've found out that addApprover(principal) can be used to add the specified principal to the list of approvers but this variable must be an instance of an ObjectReferenceIfc that refers to UserAccountIBeanIfc. But I've not been able to do it because I don't know how to retrieve the reference from the "user ID" selected in the extension field.

Thus, if addApprover command requires the use of that reference, could you let me know any example on how to do it?

Thanks for the help and best regards,

Isaac

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Isaac,

For what you are trying to do I wouldn’t recommend using Value Lists to store the user ids. It is not a scalable solution. A better approach would be to use an Object Reference extension field, so the end user can select from the list of users.

Regards,

Vikram

isaac_ariza_cruz
Participant
0 Kudos

Hi Vikram,

Thanks for your quick answer.

The reason why we had selected this kind of solution (value list) is due to our requirement needs to modify the values of this value list at runtime. Let me explain by the following example:

  • The value list is created displaying a set of users:
    • Isaac Ariza Cruz
    • John Doe
    • etc...

  • When a project is being created and before sending it to the approval flow (by changing to the corresponding phase), the author select user "Isaac Ariza Cruz". Then, the project is sent to the approval flow.

  • Now, user "Isaac Ariza Cruz" receives the notification to approve it --> Go to "My Workflow Activities" and open the project received.

  • Once the project is opened, the value list will have been updated to display only the users with authorization to be in the second level of the approval flow. Then current approver "Isaac Ariza Cruz" will select one of the approvers listed on the updated value list and send the project to the second approval level.

This is the reason why we thought the use a value list.

Anyway, we will check the Object Reference solution. But could you please let us know if this kind of extension fields allows to update the values at runtime (to fullfill requirement previously described)?

Also, it would be very appreciated if you could help me on how to retrieve the reference to the User Reference from a value of a value list (as explained in my previous post).

Thanks again for the help and best regards,

Isaac

0 Kudos

Hi Isaac,

One of the issues with this approach is that Value List you are referring to will be used by all the projects and each project might be in a different stage of the workflow approval. So if you inactivate a particular value in the value list it is going to affect all the projects.

As I had suggested earlier, using object reference would be a better approach. Typically, the approval logic will be defined in an approval matrix which is basically an extension collection. When the workflow triggers, the workflow code will read the approval matrix to determine the approvers.

For the coding part, if you have object reference extension field, you could simple use

principal = doc.getExtensionField("LEVEL1_APPROVER").get() and then pass the principal to the addApprover method.

Hope this helps.

Regards,

Vikram

isaac_ariza_cruz
Participant
0 Kudos

Hi Vikram,

 

Thanks a lot for the helpful answers.

 

Regarding the use of object reference and value list displayed in its search help: I guess that a similiar issue will be raised if we try to change value list of the the search help at runtime, isn't it? I mean, does this change will reflected only in the current project or will affect to all the projects?

 

Thanks again for the help and best regards,

Isaac

0 Kudos

Hi Isaac,

Sorry, I'm not clear what you mean by "search help".

When using object reference extension field, the system will allow the end user to select a user (approver) from the list of users from a pop up window. The contents of the popup window is basically a query that can be customized to add new filters, additional columns, etc.

Regards,

Vikram

isaac_ariza_cruz
Participant
0 Kudos

Hi Vikram,

When I say "Search help" I'm talking regarding the popup window you are referring above.

I'm aware the contect of the popup window can be customized to add new filters, etc... However, my questions are:

  1. Can this popup window content be customized at runtime?
  2. If I change the content of this popup window for a project, is this change reflected for only this project or it will affect to all the projects?

Thanks again for the help and support.

Best regards,

Isaac

0 Kudos

Hi Isaac,

The popup windows (aka picker) cannot be changed during runtime. The end user would have to pick from list of users. As I had mentioned earlier, you may want to look into creating an approval matrix on the Project type or somewhere else appropriate where you could set the rules and when the workflow triggers it can read the matrix to determine who the approvers are.  If you want to manually add the approvers, that’s fine too, but it is not possible to list the approvers dynamically.

Hope this clarifies.

Regards,

Vikram

isaac_ariza_cruz
Participant
0 Kudos

Hi Vikram,

Thanks again for the support.

Sorry for bother you again but I'm not clear what you mean by "approver matrix". Do you mean to create a extension collaboration on the project?

Thanks and regards,

Isaac

Former Member
0 Kudos

If your requirement is to change/pick second approver after first approval is done, follow below steps

1) Create another object reference extension to hold second approver. 

2) Define 2 new phases say "Waiting for level 2 approval" & "Level 2 approved".

3) Create new workflow definition with single approver (second approver).

4) Create new Phase Config. Your new config will have "Draft", "Waiting for level 1 approval" & "Level 1 approved", "Waiting for level 2 approval" & "Level 2 approved".

5) Add new workflow to phase "Waiting for level 2 approval" and old workflow to "Waiting for level 1 approval"

6) Assign new phase to your doc type.

Now you can change the second approver, when the doc is in phase "Level 1 Approved".

isaac_ariza_cruz
Participant
0 Kudos

Hi Shyam,

Thanks a lot for your answer. We are going to use this solution to cover requirement.

Best regards,

Isaac

Answers (0)