AAG885

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-14
06:24
669 views
Workflow Mapping Script
Hey All
I'm trying to get a mapping action to determine if a user is in a
particular role via a regex match.
My current code looks like this :
=======================================
//set local variables Grab Roles user is currently in
var myRoles = Array(RoleVault.getRolesUserIn(recipient));
// set the selected application as the variable for searching
var str1 = flowdata.get('start/request_form/ApplicationRoles');
//regex string for contains
var str2 = "/.*";
var str3 = ".*/";
//should result in /.*application.*/ as the regex string
var regexp = str2+str1+str3;
//loop through array search for matches
for (var i = 0; i < myRoles.length; i++) {
myRoles.match(regex)
}
=====================================
The issue is that i get in the logs TypeError: match is not a function.
I've tried adding to another variable:
var myresult = myroles
myresult.match(regex)
I'm still getting the same results in the error logs.
Anything obvious i'm missing? is there perhaps a nicer way of doing
this?
Regards,
Andrew
--
AAG885
------------------------------------------------------------------------
AAG885's Profile: https://forums.netiq.com/member.php?userid=1750
View this thread: https://forums.netiq.com/showthread.php?t=56019
9 Replies


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-14
19:53
Is var regexp a typo?
You test on regex.
You test on regex.
wschreiber1

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-15
19:35
Add some logging to see if the variables contain what what you think
they do. It seems that myRoles doesn't represent a string.
Add some error handling and check variables with something like
Packages.java.lang.System.out.println( typeof( myRoles ));
Also you may consider the API RoleVault.isUserInRole(roleDN, userDN)
Wolfgang
On 14.06.2016 07:24, AAG885 wrote:
>
> Hey All
>
> I'm trying to get a mapping action to determine if a user is in a
> particular role via a regex match.
>
> My current code looks like this :
>
> =======================================
>
> //set local variables Grab Roles user is currently in
> var myRoles = Array(RoleVault.getRolesUserIn(recipient));
>
> // set the selected application as the variable for searching
> var str1 = flowdata.get('start/request_form/ApplicationRoles');
>
> //regex string for contains
> var str2 = "/.*";
> var str3 = ".*/";
>
> //should result in /.*application.*/ as the regex string
> var regexp = str2+str1+str3;
>
> //loop through array search for matches
> for (var i = 0; i < myRoles.length; i++) {
> myRoles.match(regex)
> }
> =====================================
>
> The issue is that i get in the logs TypeError: match is not a function.
>
> I've tried adding to another variable:
>
> var myresult = myroles
> myresult.match(regex)
>
> I'm still getting the same results in the error logs.
>
> Anything obvious i'm missing? is there perhaps a nicer way of doing
> this?
>
> Regards,
>
> Andrew
>
>
they do. It seems that myRoles doesn't represent a string.
Add some error handling and check variables with something like
Packages.java.lang.System.out.println( typeof( myRoles ));
Also you may consider the API RoleVault.isUserInRole(roleDN, userDN)
Wolfgang
On 14.06.2016 07:24, AAG885 wrote:
>
> Hey All
>
> I'm trying to get a mapping action to determine if a user is in a
> particular role via a regex match.
>
> My current code looks like this :
>
> =======================================
>
> //set local variables Grab Roles user is currently in
> var myRoles = Array(RoleVault.getRolesUserIn(recipient));
>
> // set the selected application as the variable for searching
> var str1 = flowdata.get('start/request_form/ApplicationRoles');
>
> //regex string for contains
> var str2 = "/.*";
> var str3 = ".*/";
>
> //should result in /.*application.*/ as the regex string
> var regexp = str2+str1+str3;
>
> //loop through array search for matches
> for (var i = 0; i < myRoles.length; i++) {
> myRoles.match(regex)
> }
> =====================================
>
> The issue is that i get in the logs TypeError: match is not a function.
>
> I've tried adding to another variable:
>
> var myresult = myroles
> myresult.match(regex)
>
> I'm still getting the same results in the error logs.
>
> Anything obvious i'm missing? is there perhaps a nicer way of doing
> this?
>
> Regards,
>
> Andrew
>
>
AAG885

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-19
23:54
Thanks All for the feedback, There was a typeo in my variable, but i'm
still getting the same error returned after fixing.
I have tried returning the values of the variables via a LOG "comments"
process.
When i ask it to return the variable "myRoles" i get an array returned.
When i change this value to .string i can see the DN values in a string
(as i would expect).
Wolfgang, where should "Packages.java.lang.System.out.println" display
these values? Will this be in the Catalina.log for Tomcat and Server.log
for Jboss?
Regards,
Andrew
--
AAG885
------------------------------------------------------------------------
AAG885's Profile: https://forums.netiq.com/member.php?userid=1750
View this thread: https://forums.netiq.com/showthread.php?t=56019
AAG885

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-20
03:24
Found the response i was looking for in the log:
Packages.java.lang.System.out.println( typeof( myRoles));
Packages.java.lang.System.out.println(regexp);
Packages.java.lang.System.out.println(myRoles);
[STDOUT] (pool-13-thread-8) object
[STDOUT] (pool-13-thread-8) /.*FESROLE-TEST.*/
[STDOUT] (pool-13-thread-8)
[cn=secAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=roleManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=reportAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=provAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=rbpmAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=complianceAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=provManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=resourceAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=resourceManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=roleAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=FESROLE-TEST-123,cn=Level10,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services]
[STDOUT] (pool-13-thread-8) ERROR [RBPM]
[com.novell.soa.af.impl.activity.ActivityNode:handleException] Error
Evaluating Script Error Evaluating Script
com.novell.soa.script.mozilla.javascript.EcmaError: TypeError: match is
not a function.
Is the issue here that it's an object? I was under the assumption that
looping through an array would return a string.
--
AAG885
------------------------------------------------------------------------
AAG885's Profile: https://forums.netiq.com/member.php?userid=1750
View this thread: https://forums.netiq.com/showthread.php?t=56019
ScorpionSting

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-20
04:04
Best way to get more detail about what exactly is the issue is to wrap
stuff in a try clause....e.g.
Code:
--------------------
//set local variables Grab Roles user is currently in
var myRoles = Array(RoleVault.getRolesUserIn(recipient));
// set the selected application as the variable for searching
var str1 = flowdata.get('start/request_form/ApplicationRoles');
//regex string for contains
var str2 = "/.*";
var str3 = ".*/";
//should result in /.*application.*/ as the regex string
var regexp = str2+str1+str3;
//loop through array search for matches
for (var i = 0; i < myRoles.length; i++) {
try {
Packages.java.lang.System.out.println("myRoles[" + i + "]: " + myRoles.toString());
myRoles.match(regex);
}
catch(e) {
Packages.java.lang.System.out.println("Error: " + e);
}
}
--------------------
--
-"Also now available in 'G+'
(http://plus.google.com/+BenWalter-Kiwi) and 'Website'
(https://www.isam.kiwi/) format".- 😉
------------------------------------------------------------------------
ScorpionSting's Profile: https://forums.netiq.com/member.php?userid=469
View this thread: https://forums.netiq.com/showthread.php?t=56019
Visit my Website for links to Cool Solution articles.
AAG885

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-20
04:44
Thanks ScorpionSting!
From what i can see, my array only has 1 value, containing the all the
results from my query.
myRoles[0]:
[cn=secAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=roleManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=reportAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=provAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=rbpmAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=complianceAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=provManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=resourceAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=resourceManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=roleAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services,
cn=FESROLE-TEST-123,cn=Level10,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services]
What's the best way to return a multivalued attribute into an array that
i can loop?
I can using a mapping item to create a flowdata object eg:
RoleVault.getRolesUserIn(recipient) = flowdata.Currentroles
I can see in the logs it mapping roles as:
"flow-data/Currentroles[1]".setValue("cn=roleManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=Driver
Set,o=services")
"flow-data/Currentroles[2]"...etc..
but a for loop seems to only return the first result.
Cheers,
Andrew
--
AAG885
------------------------------------------------------------------------
AAG885's Profile: https://forums.netiq.com/member.php?userid=1750
View this thread: https://forums.netiq.com/showthread.php?t=56019
ScorpionSting

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-20
04:52
Try:
Visit my Website for links to Cool Solution articles.
//set local variables Grab Roles user is currently in
var myRoles = Array(RoleVault.getRolesUserIn(recipient));
// set the selected application as the variable for searching
var str1 = flowdata.get('start/request_form/ApplicationRoles');
//regex string for contains
var str2 = "/.*";
var str3 = ".*/";
//should result in /.*application.*/ as the regex string
var regexp = str2+str1+str3;
//loop through array search for matches
for (var i = 0; i < myRoles[0].length; i++) {
try {
Packages.java.lang.System.out.println("myRoles[0][" + i + "]: " + myRoles[0].toString());
myRoles[0].match(regex);
}
catch(e) {
Packages.java.lang.System.out.println("Error: " + e);
}
}
Visit my Website for links to Cool Solution articles.
ScorpionSting

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-20
05:01
What you're getting is an array of an array....
Equivalent PHP would be:
What you should really do is not array the RoleVault....
Visit my Website for links to Cool Solution articles.
Equivalent PHP would be:
Array
(
[0] => Array
(
[0] => cn=secAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[1] => cn=roleManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[2] => cn=reportAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[3] => cn=provAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[4] => cn=rbpmAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[5] => cn=complianceAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[6] => cn=provManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[7] => cn=resourceAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[8] => cn=resourceManager,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[9] => cn=roleAdmin,cn=System,cn=Level20,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
[10] => cn=FESROLE-TEST-123,cn=Level10,cn=RoleDefs,cn=RoleConfig,cn=AppConfig,cn=UserApplication,cn=DriverSet,o=services
)
)
What you should really do is not array the RoleVault....
//set local variables Grab Roles user is currently in
var myRoles = RoleVault.getRolesUserIn(recipient);
// set the selected application as the variable for searching
var str1 = flowdata.get('start/request_form/ApplicationRoles');
//regex string for contains
var str2 = "/.*";
var str3 = ".*/";
//should result in /.*application.*/ as the regex string
var regexp = str2+str1+str3;
//loop through array search for matches
if (typeof myRoles === "string")
{
myRoles.match(regex);
}
if ((typeof myRoles === "object") && (myRoles.size() > 0))
{
for (var i = 0; i < myRoles.size(); i++) {
try {
Packages.java.lang.System.out.println("myRoles.get(" + i + "): " + myRoles.get(i).toString());
myRoles.get(i).match(regex);
}
catch(e) {
Packages.java.lang.System.out.println("Error: " + e);
}
}
}
Visit my Website for links to Cool Solution articles.
AAG885

Absent Member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2016-06-20
05:36
Legended!
You are spot on, Array within an array.
I can now see a proper array. In the logs :cool:
Currently returning a null result, but it should be enough for me to work on now.
Thanks again!
You are spot on, Array within an array.
I can now see a proper array. In the logs :cool:
Currently returning a null result, but it should be enough for me to work on now.
Thanks again!