Change the identity when adding a user

Hi All, We weird dutch people having names with a word between our first name and surname. "Jan de Wolf", "Piet van Rijn", "Karel van der Casteele" See also: www.behindthename.com/.../dutch_names We want to create documents with Aras en sometimes we need to split those names in separate areas, therefore I added a property on the users Itemtype. But when creating a user automatically a identity will be created with the method AddAliasIdentity. This is a Aras core class. I would like to add this property some how to complete the string in the identity. Has any one an idea how I could solve this challenging issue. Best regards, Tom
  • Hello Tom, If I understand it right, you want to be able to set Identity name to different value than "First Name & Last Name"? If you, you can create serverMethod onAfterAdd of the ItemType Alias and then get User item from source_id property and the Identity from related_id property. Then update name property of Identity item based on properties from User item. Something like this:
    Item userItm = this.getPropertyItem("source_id"); Item identItm =this.getPropertyItem("related_id"); Item updateIdnt = this.getInnovator().newItem(identItm.getType(), "merge"); updateIdnt.setID(identItm.getID()); updateIdnt.setProperty("name", userItm.getProperty("{prop1}", "") + " " + userItm.getProperty("{prop2}") + " " + userItm.getProperty("{prop3}")); updateIdnt.apply();
  • Hello Zahar, Thank you for your suggestion. I wasn't able to get the user information on the id, so I did it the long way and that seems to work. I also needed to extend the method with a if statement so when the {prop2} is empty.
    
    Innovator inn = this.getInnovator();
    
    Item identItm =this.getPropertyItem("related_id");
    string userId = this.getProperty("source_id");
    
    Item userItem = this.newItem("User","get");
    userItem.setProperty("id",userId);
    userItem = userItem.apply();
    
    Item updateIdnt = this.getInnovator().newItem("Identity", "merge");
    updateIdnt.setID(identItm.getID());
    if (userItem.getProperty("{prop2}","") == null) 
    {
        updateIdnt.setProperty("name", userItem.getProperty("{prop1}", "") + " " + userItem.getProperty("{prop3}",""));   
    } else
    {
        updateIdnt.setProperty("name", userItem.getProperty("{prop1}", "") + " " + userItem.getProperty("{prop2}","") + " " + userItem.getProperty("{prop3}",""));
    }
    updateIdnt.apply();
    
    return inn.newResult("");
  • Happy to hear that my solution helped you. You can simplify you code: Instead (3 lines of code):
    Item userItem = this.newItem("User","get"); userItem.setProperty("id",userId); userItem = userItem.apply();
    You can use (one line of code):
    Item userItem = this.getInnovator().getItemById("User", userId);
    Instead creating if statement (5 lines of code), you can write something like (one line) :
    updateIdnt.setProperty("name", userItem.getProperty("{prop1}", "") + ( (!string.IsNullOrEmpty(userItem.getProperty("{prop2}"))) ? " " + userItem.getProperty("{prop2}") + " " : "")  + userItem.getProperty("{prop3}",""));
    If you prefer to keep the if statement, you need to update it as following:
    if (string.IsNullOrEmpty(userItem.getProperty("{prop2}"))
  • Thank you for the code improvement.