cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Substitution Rule Management

Former Member
0 Kudos

Hello gurus !!

I have a project where I have to develop a custom (or a more friendly) Substitution rule management in WD Java, but this is going to be more like an administrator where only certain users can manage the substitution of the users.

The business logic is :

  • The administrator has to select the user that is going to be "out" for a while and the user that is going take the tasks while the other user is on vacation.

  • The administrator is ging to see only the rules that he create and also he can eliimnate them.

I looked for the API [http://help.sap.com/javadocs/NW04S/current/uw/com/sap/netweaver/bc/uwl/IUWLSubstitutionManager.html|http://help.sap.com/javadocs/NW04S/current/uw/com/sap/netweaver/bc/uwl/IUWLSubstitutionManager.html]

But the cuestion that I have is how can I know the substitution rules that certain administrator has done? I could save the records on a DB but then, how can I eliminate them?

I appreciate if someone can help me on this situation

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

>But the cuestion that I have is how can I know the substitution rules that certain administrator has done? I could save the records on a DB but then, how can I eliminate them?

What do you actually mean by this? You want that the user can see only the rules that he has created? IF yes, at least I don't know how you could get this information. The substitution API does not seem to give this information (or does it). Also, in the backend in substitution rule table HRUS_D2 the creator user is not stored. Maybe it is in the portal substitution database, but I have no idea how to access that.

Regards,

Karri

Former Member
0 Kudos

Hi Karri, thanks for your answer

Actually I was afraid that someone answer me that the API doesn't have that function, but I may resolve this problem by storing the information in my DB and then just show the information to the user.

But this gave me another problem, and the proble is that the businedd logic says that the rules can be deleted, so the new cuestion is how can I delete a substitution rule, what information do I need to delete a certain substitution rule? (remember that the data is stored in a DB and this is how I can get the information)

May you help me with this?

Thanks

Former Member
0 Kudos

Hello,

For deletion there is the removeSubstitution method in the substitution API (just look behind the link that you already included in your first post). If you will be able to use the substitution API, the removal part should be easy.

I am actually a bit interested to hear the results how you get this whole substitution API working in your admin type of scenario. I have only used it for a single user (user can maintain this own substitution rules), and I remember thinking that this cannot be that easy to implement for an admin who should be able to maintain substitution for all users.

Also remember that if you need to handle only one backend system's substitutions, there are already existing functionality for that in the backend (or if not functionality - at least easy to use function modules).

Regards,

Karri

Former Member
0 Kudos

Hi Karri,

Thanks for be interested in my problem, actually i'm algo interested in how i'm going to solve this problem because I looked the API and it's looks "easy" but now that I'm using it I realize that I don't know how to start.

I know, its strange but I dont' know if you can help me with the code for getting the SubstitutionManager, becase in the API says that the substitution manager gets from IUWLService.getSubstitutionManager() but the class IUWLService is an Interface also and to implement it says that you need

(IUWLService)PortalRuntime.getRuntimeResources().getService(IUWLService.ALIAS_KEY);

I dont' know if this is correct, so I would be so gracefull if you can help me with this.

Former Member
0 Kudos

Hi,

I think that something like this will work:

IUWLService uwlService =

(IUWLService) WDPortalUtils.getServiceReference(

IUWLService.ALIAS_KEY);

There should be some document about creating custom UWL in SDN. Try to search. At least for me it was a great help, since it contained an example about the beginning part (IUWLService, etc.). Try to search also with key words such as IUWLService. I hope the document still exists somewhere in SDN.

Regards,

Karri

Former Member
0 Kudos

Hi Karri, thanks for your reply.

Actually I've been searching about this. But I have a problem with creating the substitution rule. My code is something like this:

private void saveSapSubstitution (SomeObjectBean entity) {
	IUWLService uwlService = null;
	UWLContext context = null;
	Substitution substitution = null;
	SimpleDateFormat df = new SimpleDateFormat("dd/mm/yyyy");
		
	try{
		uwlService = getUWLService();
				
		IUser sapUser = WDClientUser.getClientUser(entity.getUser()).getSAPUser();
		context = new UWLContext();
		context.setUser(sapUsuario);
		context.setLocale(new Locale("EN"));
		//uwlService.beginSession(context, 20); //This I found that has to be implemented but if I coment this line it doesn't make any change
			
		IUWLSubstitutionManager substitutionManager = uwlService.getSubstitutionManager(context);
							
		String subProfileId = null; //indica que es para todas las tareas
		String substituteId = entity.getSubstitute();
		int substitutionMode = IProviderSubstitutionManager.MODE_TAKEOVER;
		boolean switchOn = true;
		Date beginDate = df.parse(entity.getBeginDate());
		Date endDate = df.parse(entity.getEndDate());
			
		substitution = new Substitution(subProfileId, substituteId, substitutionMode, beginDate, endDate, switchOn);

		SubstitutionResult result = substitutionManager.createSubstitution(context, substitution);
			
		//uwlService.endSession(context);
			
		List badResults = result.getbadSubstitutions();
			
		if (badResults != null && badResults.size() > 0){
			String results = "";
			for(int i=0; i<badResults.size(); i++){
				results += (String) badResults.get(i) + " /";
			}
				
			throw new CustomException("Bad results:" + results);
		}
				
	}catch(Exception e){
		e.printStackTrace();
	}
		
}

private IUWLService getUWLService() throws CustomException{
	return (IUWLService) WDPortalUtils.getServiceReference(IUWLService.ALIAS_KEY);
}

With this code I can't create the substitution rule and the result is: Bad results:Unknown /. This means (at least for what I see) that the SubstitutionManager can't create the rule and the result returned has a bad result named "Unknown".

Also, I have another method for testing purpose to get the substitution rules of a user, and the code is very similar but the line in wich I call the SubstitutionManager, there I have

List substitutions = substitutionManager.getAllSubstitutions(context);

But the substitution list allways return null.

I've been searching for the error that happens when I try to create the substitution rule but I haven't found yet any information, do you have an idea or a clue of what it could be happenning?

Thanks for theinformating, I really appreciate it.

Former Member
0 Kudos

Hi,

At least you might need to set up the substitution profile. Now I can see that you set it as null, are you sure that it works? This part: String subProfileId = null;

Wasn't there some method that returns all existing substitution profiles. Then you could use one of those?

Regards,

Karri

Former Member
0 Kudos

Maybe instead of using getAllSubstitutions method you could use getAssignedSubstitutions to get the list of user's substitutions? And make sure that your user have existing substitutions...

Regards,

Karri

Former Member
0 Kudos

Hi Karr,

First of all, thanks of being consistent with my situation.

Now, about the cuestion of the substitutionProfileId = null, in one of web site it saids that the value null is for taking all the tasks of the user but if I use it I get the error "Unknown", then I tried getting the profiles with the method getSubPofile with the next code but I'm still getting the same error.

SubstitutionProfile profile = substitutionManager.getSubProfile(context, IUWLSubstitutionManager.DEFAULT_PROFILE_ALL);
			
if (profile != null){
	subProfileId = profile.getId();
}

Then I tried putting directly IUWLSubstitutionMnager.DEFAULT_PROFILE_ALL as subProfileId and with this I'm getting the next error: Bad results:Internal error returned by provider: com.sap.netweaver.bc.uwl.substitution.SubstitutionException: Thu Dec 15 09:08:10 CST 2011 (Substitution) :com.sap.security.api.NoSuchUserException:The given id "HMIPO780"is not a unique id of a user!. Check log file for details

Just for information, i'm getting the errors with the next code:

List badResults = result.getbadSubstitutions();

if (badResults != null && badResults.size() > 0){
	String results = "";
	for(int i=0; i<badResults.size(); i++){
		if(badResults.get(i) instanceof SubstitutionStatus)
			results += ((SubstitutionStatus)badResults.get(i)).getErrorMessage() + " /";
		else if (badResults.get(i) instanceof String)
			results += (String)badResults.get(i) + " /";
		else
			results += badResults.get(i).getClass() + " /";
	}
	
	throw new CustomException("Bad results:" + results);
}

I'm searching for this last error but I haven't found anything yet.

Former Member
0 Kudos

I looked to the SAP Log and I found this:

Substitution definition for user <USER.PRIVATE_DATASOURCE.un:HOIGI890> with substitute id <HMIPO780> in system: <AdHocSystem >: Failed to create subsitution from provider <AdHocWorkflowConnector> for profile <DEFAULT_ALL_TASKS>:com.sap.netweaver.bc.uwl.substitution.SubstitutionException: Thu Dec 15 14:25:52 CST 2011

(Substitution) :com.sap.security.api.NoSuchUserException:The given id "HMIPO780"is not a unique id of a user!

Former Member
0 Kudos

Hi,

Are you able to create the same substitution directly in the standard substitution application (I mean with exactly the same users and same data)? Just to make sure that there isn't something simple...

This also looks interesting:

Failed to create subsitution from provider <AdHocWorkflowConnector>

I did substitutions only to certain SAP backend system. So if I remember correctly, I had to give the backend system alias somewhere in the code. Don't remember the details anymore. Anyhow the idea was that the profiles are stored in backend system, and I had to get them from backend with one of the methods of the API. Then I displayed them for the user as a dropdown (or whatever), and then I used the profile the user selected.

I am not even sure if your problems is about the profile, so I don't know if this helps...

Regards,

Karri

Former Member
0 Kudos

Hello Karri,

Maybe you are starting to think that this problem is taing too long, but now I having another problem.

At the begining, I was deploying my Dynpro application on a local server, but this is used only to test normal dynpro apps (by normal I mean with simple functionality and no UWL functionality) but I didn't install this server and I don't know what does it have and what doesn't.

So, I decided to deploy the project on the DEV server because I know that it has the proper UWL configuration, users, roles and permission, but the problem at the begining was that DEV server weren't had the SC UWLJWF. Then the people in charge to made those things put this SC into the DEV server and made a "link" to the SC in where my Dynpro application is deployed.

In my computer I don't see any errors of reference and libraries and so, but when I made the "Check-In" to deploy my Dynpro application into the DEV server show me an activation error that saids:

[javac] ERROR: /usr/sap/DII/JC02/j2ee/cluster/server0/temp/CBS/3/.B/13543/DCs/<PATH_OF_MY_CLASS>: cannot access com.sap.netweaver.bc.uwl.IUWLService
     [javac] ERROR: bad class file: /usr/sap/DII/JC02/j2ee/cluster/server0/temp/CBS/3/.B/13543/DCs/sap.com/tc/kmc/bc.uwl/api/_comp/gen/default/public/default/lib/java/bc.uwl.service.api_api.jar(com/sap/netweaver/bc/uwl/IUWLService.class)
     [javac] ERROR: class file has wrong version 49.0, should be 48.0
     [javac] ERROR: Please remove or make sure it appears in the correct subdirectory of the classpath.
     [javac] ERROR: import com.sap.netweaver.bc.uwl.IUWLService;
     [javac] ERROR:                                 ^

Do you know what it could be happening with this version, or how could it be changed?

Once again, thanks for your answer.

(I though that I was near of a solution or at least of an answer but now I get this error ... this is my all days work)

Former Member
0 Kudos

Hi,

I have no idea about this. You might get better answers about this part in another (portal? web dynpro?) forum.

Btw, did you get those earlier problems solved?

Regards,

Karri

Former Member
0 Kudos

Hi Karri,

I'm still with the same problem of the version but at least I know now that the client install the libraries for SAP 7.3 and we are using the 7.0v, so I'm wating that they change the version so I could test the application.

But I can't tell you if the problem is resolved until they change the version.

Thanks for your help and when I get an answer I will tell you the good or bad news.

Former Member
0 Kudos

Hi Karri,

Finally the libraries are now correct. I tried creating a substitution rule with the substitution rule management and it seems that there was no problem, and then I tried to create a substitution rule with my custom substitution rule management and these was the error:

Invalid portal user ID for system

I've been looking for this error and this is what I found:

"Invalid portal user id for system (Less common)

Check if user mapping is required or the length of the user Id is too long for the system."

see [http://help.sap.com/saphelp_nw70/helpdata/en/0b/1fc20097b74c41b38621ec2a9454bb/content.htm|http://help.sap.com/saphelp_nw70/helpdata/en/0b/1fc20097b74c41b38621ec2a9454bb/content.htm]

Have you got this error before?

I want to ask you something else, I've been searching on the posibility of doing what I want to do but I found [this blog |http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/16356]when it says that the UWL only works with the user that is logged in for security reasosns, so I want to know if for the substitution rules is the same issue because if I end my project but there's no way to work like I want it (when a third person manage the substitution rules of other users) so I need it to know for don't waste more time.

Thanks.

Former Member
0 Kudos

Hi,

I don't remember seeing this error. You are probably using some kind of wrong type of user object or whatever. If you create the substitution with the standard application, I assume that you are able to do it successfully? Then of course you should be able do it with your custom application.

I would recommend that you create few substitutions with the standard application. Then develop a code that you can use to display the existing substitutions for example in a table. This should show you that in which format the user IDs etc. must be given to the substitution creation method.

Regards,

Karri

Former Member
0 Kudos

>I want to ask you something else

This is an interesting issue, and if I remember correctly I might have mentioned about this in one of my first answers. I simply don't know whether it will work. In my project I was thinking this same stuff that it would be cool if other users (admins) could manage other users substitutions, and I even spend few moments of taking a look if it is possible.

In the blog there is this part:

IUser user = //TODO Get the user for whom the items are to be retrieved.

uwlContext.setUser(user);

uwlContext.setLocale(Locale.getDefault());

I remember trying to play with these (to set other user or whatever - I don't remember the details). It didn't work immediately, so I left this approach fast, since it wasn't really a requirement. After you manage to get the substitution work for yourself, you might do few tests to make it work for other users. Or you could contact the guy(s) from the blog and ask them what they mean.

I still also want to remind you that there is existing ready to use transaction to maintain other users substitutions in backend system. There are also functions (SAP_WAPI*) for maintaining substitutions in backend, so you could easily develop a web dynpro application based on those. Of course then you need to manage possibly several backend systems (let's say you have ERP, SRM, HR), which makes things a bit more complicated.

Regards,

Karri

Former Member
0 Kudos

Hi Karri,

As always, thanks for your answers and let me tell you that I can finally create substitution rules from my application. But I'm getting the issues that are mentioned on the blog that I told you before: the uwl takes the logged in user for security reasons.

And I checked that because I create a substitution rule with the admin (logged in user) when user X takes tasks from user Y.

I checked on the table RHUS_D2 and it looks that the substitution rules was created for the user admin and not for the user X.

I'm going to search a little more about this situation, but also I want to ask you about those abap functions that you mentioned before.

I know that I can call abap functions with RFC's from my dynpro application.

Thanks,

Former Member
0 Kudos

Hi,

Let me know if you can make it work for other users than the one logged in.

About the functions...

First of all, log in to the backend system and take a look to report R*SET_SUBSTITUTE or SETSUBSTIT* (cannot remember the exact name). You can use that to maintain users' substitutions (=>it will update table RHUS_D2). If you can teach your users to use that report, you might not even need any custom portal application.

Well, I guess you have some specific requirements and the report will not fulfill them. Then take a look to the SAP_WAPISUBST functions in SE37. There should be function for every possible action (creation, deletion, etc.). IF you know any ABAP, the functions are self explanatory when you take a look to them. They will just basically update the table RHUS_D2. You can easily call these from your Java web dynpro application (if I remember correctly the functions are RFC enabled). Anyhow, as I said before, if you have multiple different backend systems, you might need to make the calls to all of them => not very nice, and in this kind of situation the Java based API solution is much better. If you just one backend system, and want to use the functions, I would even prefer using ABAP web dynpro rather than Java due to WDA's several nice features.

Regards,

Karri

Former Member
0 Kudos

Hi Karri,

First of all, an apologyze because I finished my custom substitution manager a few weeks ago and I didn't told you.

Let me tell you how I did it:

1. I create a table on a DB when it is going to save the user who creates the rule, the user that is going to be ausent and the user that is going to suply them. (I also create a simple ABC stored procedure wich is going to create, delete or consult the substitution rules).

2. I create two views in WebDynpro JAVA: one for consult the substitution rules created by the logued in user and one for create the substitutions rules.

3. The view for consult is very simple because I just display the substitutions rules created by the logued in user using the stored procedures that I create. I also give a button to delete a certain rule and this button calls the HR_SUBSTITUTE_DELETE function with a RFC Model, once that it is deleted from the system I delete the substitution rule from my DB.

4. The second view is to create the substitution rule and I need to call the HR_SUBSTITUTE_MAINTAIN function with a RFC Model. I send the user to be out, suplier, start and end date (the users are selected in a combo box).

The only thing that I haven't time to ask you again or to investigate is that when I have the next substitution rules:

USER                 SUBSTITUTE                 START DATE                END DATE               ACTIVE
A                     B                          25/02/2012                 25/02/2012            Y
A                     B                          28/02/2012                 04/05/2012            Y
...

When I tried to delete the first substitution rule (the one that is just for the 25/02/2012) the function HR_SUBSTITUTE_DELETE deletes all the substitutions rules that I created for the users A-B.

The solution for me is to validate that it can only be one substitution rule for the users A-B so, when I try to delete it, it only delete one substitution rule at the time.

But this I implemented because I don't have any more time.

So, thanks a lot for your help and sugestions. I also wanted to develop the requirement with the API of JAVA but it appers to have security things that only permits to develop substitution rules for the logued in user and not for the user that you stablished.

Former Member
0 Kudos

Hi,

Thanks for update!

Regards,

Karri

Answers (1)

Answers (1)

Former Member
0 Kudos

HI Karri, All,

Hoping that you can help, and please ignore my limited knowledge as I am functional resources and not technical.

Query: We are trying to amend the standard functionality of subtitution, by adding some conditions. We have added fro MSS, MSS leave and Finance and which works fine, but the developer isn't really able to do for ALL option. When raised with SAP they gave an option of amending  interface "IProviderSubstitutionManager.getSubProfiles" in SAP. Can you tell me if this possible and secondly how do I access this interface.

Regards

Sanj