Groups > Novell > Identiry Manager Workflow applications > Re: CN Generation in a Mapping Activity?? Modify existing code?




CN Generation in a Mapping Activity?? Modify existing code?

CN Generation in a Mapping Activity?? Modify existing code?
Wed, 07 May 2008 19:28:05 GMT
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);

Post Reply
Re: CN Generation in a Mapping Activity?? Modify existing code?
Thu, 08 May 2008 01:16:02 GMT
If you move you code into a mapping activity you will no longer be able
to alert the user if they have chosen a valid CN....or is that just for
testing?

If the user provides an email address in the login form then you could
email it to them after the account is created.

To move the code from the submit action intercept to a mapping rule you
will need to do a few things.

1. Remove all the code from the onload event.

2. Make sure that the fn and sn fields are mapped in the post activity
flowdata of the Start activity.

3. Add a Mapping Activity after the Start Activity.

4. Copy the code to the source expression of the Mapping Activity and
change your code to get fn and sn variables from the flowdata.

var fn = flowdata.get('start/request_form/GivenName');
var ln = flowdata.get('start/request_form/Surname');

5. Ad a target expression to the mapping Activity. You may need to
create a hidden field on the form to put the new CN into. Should
somthing like:-

flowdata.start/request_form/tmpCN

6. Remove the alerts from you code.

7. Change the Entity DN to use the new flowdata attribute.

flowdata.getObject('start/request_form/tmpCN')

8. Add some kind of user notification for the generated CN.



Another approach for this kind of this is to create the user in a temp
location in the IDVault and let IDM take care of unique CN generation.
Once a unique CN is generated then rename and move the object to
correct location. This process then allows other systems to feed users
into the IDVault and follow the same process for naming accounts. This
can also be done in pure DirXML script which is a lot nicer than
ECMA...and probably faster and less error prone.

Hope that helps.

Rowan



Rob.S;1552893 Wrote: 
> 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);


-- 
Misterwippy
------------------------------------------------------------------------
Misterwippy's Profile: http://forums.novell.com/member.php?userid=170
View this thread: http://forums.novell.com/showthread.php?t=327022
Post Reply
Re: CN Generation in a Mapping Activity?? Modify existing code?
Thu, 08 May 2008 13:53:41 GMT
Rowan,

Excellent, across the board.  Thanks.  In response to your 
questions/comments:

1.  The alert for telling the user what their CN is was used in a different 
workflow, and would be eliminated from this one.  The user will receive an 
e-mail as you suggest.

2.  Since I was going to have to do some IDM based manipulation anyway 
(generating a password and e-mail to the user), it makes immense sense to 
just do the whole generateCN/rename/move/email process in policy.  Great 
idea!

Thanks!!

Rob


"Misterwippy" <Misterwippy@no-mx.forums.novell.com> wrote in
message 
news:Misterwippy.392hwn@no-mx.forums.novell.com...
>
> If you move you code into a mapping activity you will no longer be able
> to alert the user if they have chosen a valid CN....or is that just for
> testing?
>
> If the user provides an email address in the login form then you could
> email it to them after the account is created.
>
> To move the code from the submit action intercept to a mapping rule you
> will need to do a few things.
>
> 1. Remove all the code from the onload event.
>
> 2. Make sure that the fn and sn fields are mapped in the post activity
> flowdata of the Start activity.
>
> 3. Add a Mapping Activity after the Start Activity.
>
> 4. Copy the code to the source expression of the Mapping Activity and
> change your code to get fn and sn variables from the flowdata.
>
> var fn = flowdata.get('start/request_form/GivenName');
> var ln = flowdata.get('start/request_form/Surname');
>
> 5. Ad a target expression to the mapping Activity. You may need to
> create a hidden field on the form to put the new CN into. Should
> somthing like:-
>
> flowdata.start/request_form/tmpCN
>
> 6. Remove the alerts from you code.
>
> 7. Change the Entity DN to use the new flowdata attribute.
>
> flowdata.getObject('start/request_form/tmpCN')
>
> 8. Add some kind of user notification for the generated CN.
>
>
>
> Another approach for this kind of this is to create the user in a temp
> location in the IDVault and let IDM take care of unique CN generation.
> Once a unique CN is generated then rename and move the object to
> correct location. This process then allows other systems to feed users
> into the IDVault and follow the same process for naming accounts. This
> can also be done in pure DirXML script which is a lot nicer than
> ECMA...and probably faster and less error prone.
>
> Hope that helps.
>
> Rowan
>
>
>
> Rob.S;1552893 Wrote:
>> 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);
>
>
> -- 
> Misterwippy
> ------------------------------------------------------------------------
> Misterwippy's Profile: http://forums.novell.com/member.php?userid=170
> View this thread: http://forums.novell.com/showthread.php?t=327022
> 

Post Reply
about | contact