Symantec IGA

 View Only
Expand all | Collapse all

BLTH for UserID creation CA IDM 14.2

  • 1.  BLTH for UserID creation CA IDM 14.2

    Posted May 08, 2018 09:28 AM

    I am looking for a blth where i need to create a user ID based on following conditions

    UserID=(First Character of First Name + First character of Last Name + 'a' + DepartmentNumber )

    For Example

    First name Randeep

    Last Name Singh

    Deaprtment 0200

    UserID = rsa0200 

    if the generated user id already exist then we can increment the character at 3 position to b.

    in that case new UserID will be rsb0200

     

    can you please share your suggestion



  • 2.  Re: BLTH for UserID creation CA IDM 14.2
    Best Answer

    Broadcom Employee
    Posted May 09, 2018 06:11 AM

    Hi Randeep,

     

    I wrote this quick sample for you.

     

    You should not encounter obstacles.

    Adapt with your department Number attribute name or well known name and other specific requirements.

    Do not hesitate to download and review the programming java doc.

    https://docops.ca.com/ca-identity-manager/14-1/EN/files/410665376/410665377/1/1479144421210/im_javadoc.zip

     

    Regards,

    Philippe.



  • 3.  Re: BLTH for UserID creation CA IDM 14.2

    Posted May 10, 2018 09:16 AM

    Hi Philippe,

     

    Thanks for your prompt reply.

    I am not into much into coding part, but i see this code is for server level. 

    But i am looking for a UI based code for BLTH.

    can you please share the code for BLTH which i can use for my 'Create Empoyee' task.

    Because if i copied your code to Create Employee task into BLTH i got this error message attached.



  • 4.  Re: BLTH for UserID creation CA IDM 14.2

    Broadcom Employee
    Posted May 13, 2018 08:40 AM

    Hi Randeep,

    I was off last couple of days.

    Here is what it could be in JavaScript due to to some differences with datatypes and exceptions catching:

    Regards,

    Philippe.



  • 5.  Re: BLTH for UserID creation CA IDM 14.2

    Posted May 14, 2018 04:27 AM

    Hi Phillippe,

     

    Thanks for the help.

    I have actually tried your code but still getting error when I tried to submit the task.

    Please find the code attached below.

    function handleValidation(blthContext, errorMsg) {
      
      var user = blthContext.getUser();
      var FirstName = user.getAttribute("%FIRST_NAME%");
      var LastName = user.getAttribute("%LAST_NAME%");
      var departmentNumber = user.getAttribute("l");
      if (FirstName.isEmpty() || LastName.isEmpty() || departmentNumber.isEmpty()) {
       // this message will be presented on the Screen 
       errorMsg.reference = ("Failed to build an UID, First name, last name and department number are required");
       return false;
      }
      var UID = FirstName.substring(0, 1) + LastName.substring(0, 1) + "a" + departmentNumber;
      var userbis = blthContext.getUserProvider();
      for (var c="a".charCodeAt(0); c<="z".charCodeAt(0); c++){
      try {
       UID = FirstName.substring(o, 1) + LastName.substring(0, 1) + String.fromCharCode(c) + departmentNumber;
       userbis.findUser(UID, null);
       //UID already exists, search for next computed one
       if (c=="z".charCodeAt(0)) {
        // this message will be presented on the Screen
        errorMsg.reference = "Failed to find an UID,all UIDs already exist";
        return false;
        }
       } catch (nso){
       break; //Not such object
       }
      }
      try {
       blthContext.getUser().setAtttribute("%USER_ID%", UID);
      } catch (ex) {
       //this message will be presented on the screen
       errorMsg.reference = "Failed to set an UID" + ex.getMessage();
       return false;
       }
      return true;
     }
    Error message


  • 6.  Re: BLTH for UserID creation CA IDM 14.2

    Broadcom Employee
    Posted May 14, 2018 06:34 AM

    Hi Randeep,

     

    I see 3 typos:

    Line 10 should be (no parenthesis):

    errorMsg.reference = "Failed to build an UID, First name, last name and department number are required";

     

    Line 18 should be (starting index in first sub string is zero not o):

    UID = FirstName.substring(0, 1) + LastName.substring(0, 1) + String.fromCharCode(c) + departmentNumber;

     

    Line 31 should be (setAtttribute function does not exist):

    blthContext.getUser().setAttribute("%USER_ID%", UID);

     

    Regards,

    Philippe.



  • 7.  Re: BLTH for UserID creation CA IDM 14.2

    Posted May 15, 2018 03:37 AM

    Hi Philippe,

     

    Thanks for the help. With some little modification i am able to execute the code as per my requirement.

     

    I have one more requirement, Where I need to fetch some attribute(based on the query filter) from a Ldap store  in the same script I have prepared with your help.

     

    Thanks,

    Randeep.



  • 8.  RE: Re: BLTH for UserID creation CA IDM 14.2

    Posted Jun 29, 2020 11:10 AM
    Hi Philippe, 

    I have written code for uniqueness check of email as like user id, but it's not working.

    Requirement is Firstname+Lastname+n@domain, 'n' should vary from 1-99.

    Please find below code and suggest if I missed anything

    function handleValidation(blthContext, errorMsg) {

    var user = blthContext.getUser();
    var FirstName = user.getAttribute("%FIRST_NAME%");
    var LastName = user.getAttribute("%LAST_NAME%");
    if (FirstName.isEmpty() || LastName.isEmpty()) {
    // this message will be presented on the Screen
    errorMsg.reference = "Failed to build an mail, First name and last name are required";
    return false;
    }
    var mail = FirstName + "." + LastName+ "0" + "@adek.gov.ae";
    var userbis = blthContext.getUserProvider();
    for (var n=0; n<=99; n++){
    try {
    mail = FirstName + "." + LastName+ n + "@adek.gov.ae";
    userbis.findUserDuplicate(mail, null);
    //mail already exists, search for next computed one
    if (n==99) {
    // this message will be presented on the Screen
    errorMsg.reference = "Failed to find an mailID,all mailIDs already exist";
    return false;
    }
    } catch (nso){
    break; //Not such object
    }
    }
    try {
    blthContext.getUser().setAttribute("%EMAIL%", mail);
    } catch (ex) {
    //this message will be presented on the screen
    errorMsg.reference = "Failed to set an mail" + ex.getMessage();
    return false;
    }
    return true;
    }


  • 9.  Re: BLTH for UserID creation CA IDM 14.2

    Broadcom Employee
    Posted May 16, 2018 03:31 AM

    Hi Randeep,

     

    I think I answered to the original question.

    Your last requirement is not clear enough for me.

    You have all the elements to meet your expectations.

    Again please consult the mentioned java doc to help you in this task.

     

    Best Regards,

    Philippe.



  • 10.  Re: BLTH for UserID creation CA IDM 14.2

    Posted May 22, 2018 09:56 AM

    Hi Philippe,

     

    Thanks for your help.

    We have modified the code and it is working fine as per expectation if we tries to set %USER_ID%.

    But if we tries to set another unique attribute in our case it is %FAX%. This code didn't worked as expected.

    Every time it creates the FAX attribute as 'rsa0200'. As shown below.

    UserID=(First Character of First Name + First character of Last Name + 'a' + DepartmentNumber )

    For Example

    First name Randeep

    Last Name Singh

    Deaprtment 0200

    FAX= rsa0200 

     

     

    function handleValidation(blthContext, errorMessage) {
    thisSCRIPT="Test BLTH" ;
    pout = Packages.java.lang.System.out ;
    trace = false;
    if (trace) pout.println( thisSCRIPT + " starting..." ) ;

    errors = false ;
    errorMsg="";
    thisUser = blthContext.getUser() ;
    thisTASK = blthContext.getTaskFriendlyName() ;
    FirstName = blthContext.getUser().getAttribute("%FIRST_NAME%");
    LastName = blthContext.getUser().getAttribute("%LAST_NAME%");
    departmentNumber = blthContext.getUser().getAttribute("l");


    var combine =FirstName.substring(0, 1) + LastName.substring(0, 1) + "a" + departmentNumber
    var userbis = blthContext.getUserProvider();

    for (var c="a".charCodeAt(0); c<="z".charCodeAt(0); c++){
    try {
    combine = FirstName.substring(0, 1) + LastName.substring(0, 1) + String.fromCharCode(c) + departmentNumber;
    userbis.findUser(combine, null);

    //UID already exists, search for next computed one
    if (c=="z".charCodeAt(0)) {
    // this message will be presented on the Screen
    errorMessage.reference = ("Failed to find an UID,all UIDs already exist");
    return false;
    }
    } catch (nso){
    break; //Not such object
    }
    }
    try {
    thisUser.setAttribute( "%FAX%" , combine.toUpperCase() ) ;

    }catch (ex) {}
    if (errors) {
    errorMessage.reference = errorMsg ;
    if (trace) pout.println( thisSCRIPT + " ending - false" ) ;
    return false ;
    }
    if (trace) pout.println( thisSCRIPT + " ending - true" ) ;
    return true ;
    }

     

    Thanks.