cajitq

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-01-08
09:13
598 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
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
2 Replies
Anonymous_User

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-01-08
16:06
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
>
>
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
>
>
cajitq

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-01-09
09:22
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
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