Greetings,

I have a lovely bunch of code that generates a CN for a new User Entity,
when the recipient submits the workflow. This relies on a global query,
which works great when the recipient is a logged in user, but fails
miserably when trying to have an unauthenticated user request a resource via
the "request Resource" portlet. (i.e. external user self-registration)

It was suggested to me that I try to achieve the CN generation in a mapping
activity, which sounds ideal to me, but I don't know how to "de-couple" the
existing code from its current tie to the "submit" action on the request
form.

1. In short... what do I get rid of in the following code to make it work
in a mapping activity? I assume all references to field and form have to
go... but ???

and
2. Where do I put this script... in the source expression or target
expression. I assume "source" as I have a flowdata.cn available to put the
results into, in the target expression.

Thanks for any assistance you can offer.

The following is currently found in an "onLoad" event on the "cn" field on
my request form.
===============================================
field.hide();
//The following Computes a Unique CN;
window.computeCN = function (invocation)
{
try {
var errors = form.validate();
if (errors) {
invocation.proceed();
return;
}
// Unique CN Generation;
var fn = form.getValue('GivenName');
var ln = form.getValue('Surname');
var cn;
var prefix=(ln.substring(0, ln.length > 5 ? 5 :
ln.length) + fn.substring(0, 1)).toLowerCase();
for (var i = 0; i <99; i++) {
// First iteration cn does not have a number appended. Subsequent loops get
incrementing counter;
cn = prefix + (i == 0 ? "" : i);
form.setValues('cn', cn);
// form.showMsg("Variable cn is set to " + cn);
try {
// A query object called "uniqueCN is passed a filtering parameter... the
computed cn value.;
var v = IDVault.globalQuery(null,
"uniqueCN", {"cN":cn})
// form.showMsg("Variable V is set to " + v);
// form.showMsg("Variable V[0] is set to " +
v[0]);
// form.showMsg("Variable V is set to " +
v[1]);
} catch (e) {
alert(e);
break;
}
// The global query returns an array: V[0] is the dn of an object with a
matching cn and v[1] is the cn;
// if (v[1] == cn) {;
if (v[1] != "") {
form.showMsg("cn " + cn + " already exists
at " + v[0]);
} else {
alert("This User's Unique Login ID= " + cn);
invocation.proceed();
break;
}
}
} catch (e) {
alert(e);
}
};
form.interceptAction("SubmitAction", "around",
window.computeCN);