Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Highlighted
cajitq Absent Member.
Absent Member.
469 views

Calling builtin Java functions from workflow (Between forms)

Hi everyone.

Long ago I stumpled upon a cool solution that enabled renaming of objects from a workflow between forms. This is working perfectly, and now I'm trying to modify attributes using the same approch, but I'm having some problems with this and I was hoping that some of you guys could help me here.

This is the working script that makes it possible to rename objects between forms:

function doRename()
{
var result = "";
try
{
var data = ScriptVault.JSON.parse( flowdata.get('wfData') )
var cn = flowdata.get('name');
var ctx = Packages.com.sssw.fw.directory.api.EboDirectoryFactory.getConnMgr().getAdminContext( false );

var oldDN = flowdata.get('dn');
var newDN = 'cn='+ cn + ','+ data.templateJSON.constants.groupPlacement;

ctx.rename( oldDN, newDN );
ctx.close();
result = newDN;
}
catch (e)
{
result = " ldapRenameOrMove () " + e.toString();
}
return( result );
}
doRename();


As you can see I'm getting the Java LDAP context (cxt) and I'm able to call ctx.rename(string, string).

But when trying to call the methos modifyAttributes I'm getting errors no matter what I do, I this it has to do with datatypes between ECMA and Java but I'm not totally sure.

Here is my new script that is failing:

function updateAttribute() {
var result = "";
try {
var operations = ScriptVault.JSON.parse(flowdata.get('operations'));
var ctx = Packages.com.sssw.fw.directory.api.EboDirectoryFactory.getConnMgr().getAdminContext(false);

var dn = ScriptVault.JSON.parse(flowdata.get('wfData')).objectDN;
for (var key in operations) {
var current = operations[key];
if (current.added.length > 0) {
for (var i in current.added) {
var value = current.added;
var attribute = current.attribute;
var basicAttribute = new javax.naming.directory.BasicAttribute(attribute, value);

ctx.modifyAttributes(new java.lang.String(dn), javax.naming.directory.DirContext.ADD_ATTRIBUTE, basicAttribute);
}
}
}

ctx.close();
java.lang.Thread.sleep(5000)
} catch (e) {
result = "Error in updateAttribute(): " + e.toString();
}
return (result);
}
updateAttribute();

Here is the Error I get:
2019-01-04 15:01:13,587 [INFO] Organisatorisk funktion (KOMBIT) Error in updateAttribute(): InternalError: Can't find method com.sun.proxy.$Proxy26.modifyAttributes(java.lang.String,number,javax.naming.directory.BasicAttribute). 23 0

As you can see it's complaining about not having a method with the given parameters (datatypes). the documentation states that this method exists:
void modifyAttributes(String name,
int mod_op,
Attributes attrs)
throws NamingException

It takes a String an int and a Attributes interface (BasicAttribut that I'm using implements this interface)

Anyway. Is there anyone here that knows if this is possible and if so, can see what I'm doing wrong.

All inputs is appreciated

Kind Regards
Carsten
Labels (1)
Tags (2)
0 Likes
2 Replies
Anonymous_User Absent Member.
Absent Member.

Re: Calling builtin Java functions from workflow (Between forms)

The error seems to indicate that you're passing "BasicAttribute", while
the method expects "BasicAttributes"

BasicAttribute implements Attribute
BasicAttributes implements Attributes

Have you tried passing something like

var basicAttributes
= new javax.naming.directory.BasicAttributes(attribute, value);

Wolfgang

On 08.01.2019 10:14, cajitq wrote:
>
> Hi everyone.
>
> Long ago I stumpled upon a cool solution that enabled renaming of
> objects from a workflow between forms. This is working perfectly, and
> now I'm trying to modify attributes using the same approch, but I'm
> having some problems with this and I was hoping that some of you guys
> could help me here.
>
> This is the working script that makes it possible to rename objects
> between forms:
>
> -function doRename()
> {
> var result = "";
> try
> {
> var data = ScriptVault.JSON.parse( flowdata.get('wfData') )
> var cn = flowdata.get('name');
> var ctx =
> Packages.com.sssw.fw.directory.api.EboDirectoryFactory.getConnMgr().getAdminContext(
> false );
>
> var oldDN = flowdata.get('dn');
> var newDN = 'cn='+ cn + ','+
> data.templateJSON.constants.groupPlacement;
>
> ctx.rename( oldDN, newDN );
> ctx.close();
> result = newDN;
> }
> catch (e)
> {
> result = " ldapRenameOrMove () " + e.toString();
> }
> return( result );
> }
> doRename();-
>
> As you can see I'm getting the Java LDAP context (cxt) and I'm able to
> call ctx.rename(string, string).
>
> But when trying to call the methos modifyAttributes I'm getting errors
> no matter what I do, I this it has to do with datatypes between ECMA and
> Java but I'm not totally sure.
>
> Here is my new script that is failing:
>
> -function updateAttribute() {
> var result = "";
> try {
> var operations = ScriptVault.JSON.parse(flowdata.get('operations'));
> var ctx =
> Packages.com.sssw.fw.directory.api.EboDirectoryFactory.getConnMgr().getAdminContext(false);
>
> var dn = ScriptVault.JSON.parse(flowdata.get('wfData')).objectDN;
> for (var key in operations) {
> var current = operations[key];
> if (current.added.length > 0) {
> for (var i in current.added) {
> var value = current.added;
> var attribute = current.attribute;
> var basicAttribute = new
> javax.naming.directory.BasicAttribute(attribute, value);
>
> ctx.modifyAttributes(new java.lang.String(dn),
> javax.naming.directory.DirContext.ADD_ATTRIBUTE, basicAttribute);
> }
> }
> }
>
> ctx.close();
> java.lang.Thread.sleep(5000)
> } catch (e) {
> result = "Error in updateAttribute(): " + e.toString();
> }
> return (result);
> }
> updateAttribute();
> -
> Here is the Error I get:
> 2019-01-04 15:01:13,587 [INFO] Organisatorisk funktion (KOMBIT) Error in
> updateAttribute(): InternalError: Can't find method
> com.sun.proxy.$Proxy26.modifyAttributes(java.lang.String,number,javax.naming.directory.BasicAttribute).
> 23 0
>
> As you can see it's complaining about not having a method with the given
> parameters (datatypes). the documentation states that this method
> exists:
> void modifyAttributes(String name,
> int mod_op,
> Attributes attrs)
> throws NamingException
>
> It takes a String an int and a Attributes interface (BasicAttribut that
> I'm using implements this interface)
>
> Anyway. Is there anyone here that knows if this is possible and if so,
> can see what I'm doing wrong.
>
> All inputs is appreciated
>
> Kind Regards
> Carsten
>
>

0 Likes
cajitq Absent Member.
Absent Member.

Re: Calling builtin Java functions from workflow (Between fo

Hi Wolfgang.

Thank you very much for pointing that out, this was indeed the problem and my script is working now. I'm a little embarrassed that I didnt see that myself, I've been looking at this for hours - Oh well that's just how it is sometimes.

Thank you for taking your time to help me out here.

Cheers
Carsten
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.