cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete users from CLM using script?

Former Member
0 Kudos

Hello Experts,

I'm using CLM and in our system we have a lot of user accounts which are not used. When I check in our db the column name "date_last_loggedin" it is null. I would like to delete all that type of accounts, so I was trying to do this with one of our test accounts and I was using this script:


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

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

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

import com.sap.odp.api.doc.DocLinkDefinitionTypeEnumType;

import com.sap.odp.api.doc.DocumentLinkIBeanIfc;

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

import java.io.PrintWriter;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.io.FileOutputStream;

import com.sap.eso.api.doccommon.doc.contract.*;

import java.util.Hashtable;

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

import java.util.Calendar;

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

import com.sap.odp.api.doccommon.userdefined.*;

import com.sap.eso.api.contracts.*;

import java.util.List;

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


userHome = (AbsAccountHomeIfc)HomeLocator.lookup(session, "upp.user_account");

String userID = "testuser1";

user = (AbsAccountIfc)userHome.findUniqueByName(userID);

userHome.delete(user);

But I got an error "Database error: The record cannot be removed because it is currently active.". When I changed user to be Inactive and ran code again I got another error "You cannot modify the business object because it is not editable. Click Edit This Document at the top of the page to make this document editable.".

Have you got idea how to delete users using script(this is my goal) and solve this problem?

Thanks for help.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Please use

userHome.upgradeToEdit(user);

userhome.delete(user):


Former Member
0 Kudos

Hello,

With help of Venkateswararao Vasantha I made a change in my code, now it looks like below:


user = (AbsAccountIfc)userHome.findUniqueByName(userID);

userHome.upgradeToEdit(user);

userHome.delete(user);

userHome.save(user);

This code is in try-catch block. When I ran the code again it went to catch section suggesting potential error, but when I save the result of Exception - e.getMessage() it gives me only string with "null".

How to solve this problem and what to do next?

Thanks for your help.

former_member190023
Contributor
0 Kudos

Hi Marc,

The question is: "why would you save something which is already deleted?".

The answer will tell you why you're getting a 'null' error.

Bogdan

Former Member
0 Kudos

Hi Bogdan,

I thought this is some kind of commit in this operation. But when I removed the last line with save method I still get "null" string as result of exception message. Some other idea what is wrong?

Thanks for help.

former_member190023
Contributor
0 Kudos

Hmm, sorry for the 'pun'

If you have access to the logs, you need to check the full stack trace. But ... by the looks of things it might not be possible to fully delete the user.

I'll do some checking and get back; maybe you could also get your hands on the stack trace (you can check online how to write it to a string using PrintWriter)

Bogdan

Former Member
0 Kudos

Hi Bogdan,

As you mentioned I printed the stack trace and found entry like java.lang.UnsupportedOperationException so you where right that this kind of operation is not possible.

Thanks for your suggestion on last message it pointed me where to look.

Best Regards