Groovy script to update User status

Hi groovy people. I am trying to run an event in Agile that runs once a day.
It finds all LDAP users that have been recently created in the past 3 days and are not Active yet.  I then want the groovy script to make them Active.

The event monitor gives me this output:

Message: Begin event – me testing
…before exec query…
…after exec query…
User: bsmith
Insufficient privilege.

So, it does find the AGILEUSER records, but then fails with that privilege message.
In the Event Handler, I put this in the Role field: Administrator;User Administrator
Is this not the correct privilege?

The groovy code in the Event Handler looks like this:

import com.agile.agileDSL.ScriptObj.*;

import com.agile.api.*;

import com.agile.px.*;

import com.agile.util.sql.*;

import java.sql.*;
void invokeScript(IBaseScriptObj obj) {
Connection connection = null;

PreparedStatement statement = null;

ResultSet rows = null;

IAgileSession m_session = obj.getAgileSDKSession();
obj.logMonitor( "Begin event - me testing" );
try {

connection = ConnectionFactory.getFactory().getConnection();

statement = connection.prepareStatement("SELECT LOGINID FROM AGILEUSER WHERE ENABLED = 0 AND AUTH_SRC LIKE 'LDAP%' AND DATE_CREATED > (SYSDATE-3)");

obj.logMonitor( "...before exec query..." );

rows = statement.executeQuery();

obj.logMonitor( "...after exec query..." );

while(rows.next()) {

// modify user status

obj.logMonitor( "User: " + rows.getString("LOGINID") );

IUser user = (IUser)m_session.getObject(IUser.OBJECT_TYPE, rows.getString("LOGINID"));

obj.logMonitor( "...after IUser..." );

IAttribute attr = (String)user.getValue(UserConstants.ATT_GENERAL_INFO_STATUS);

obj.logMonitor( "attr = " + attr );

if ( attr == "Inactive" ) {

user.setValue(UserConstants.ATT_GENERAL_INFO_STATUS, "Active");

obj.logMonitor( rows.getString("LOGINID") + " Activated" );

}

}
} catch (Exception e) {

obj.logMonitor( e.getMessage() );

}

}
Agile Talent Asked on December 13, 2019 in Software Development Kit (API).
Add Comment
3 Answer(s)

Hello

I see roles like My User Profile and Creator can discover object he or she created missing. Please make sure this event has all the roles a regular “User administrator” in your company would have

– Raj

 

Agile Angel Answered on December 14, 2019.
Add Comment

What user account is the PX running as??? Does that user have all needed user administrator privileges and roles?

And I agree with Raj, make darn sure you always add default roles to the user before you make them active.

Agile Angel Answered on December 14, 2019.
Add Comment

Thank you Raj and Kevin.  I added more roles to the Event Handler and then it worked.  And I also needed to change  IAttribute  to  String .  I had found that code somewhere, maybe in one of these forums.  When a user gets created from LDAP, it is automatically giving it the Roles ‘Creator can read and discover object he or she created’ and ‘My User Profile’.  Now, I also want to update the User Category to ‘Concurrent’ and also add the user to a User Group.

Agile Talent Answered on December 14, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.