<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Change the identity when adding a user</title><link>https://www.aras.com/community/f/development/3339/change-the-identity-when-adding-a-user</link><description>Hi All,

We weird dutch people having names with a word between our first name and surname.
&amp;quot;Jan de Wolf&amp;quot;, &amp;quot;Piet van Rijn&amp;quot;, &amp;quot;Karel van der Casteele&amp;quot; 
See also: www.behindthename.com/.../dutch_names 

We want to create documents with Aras en sometimes</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Change the identity when adding a user</title><link>https://www.aras.com/community/thread/757?ContentTypeID=1</link><pubDate>Mon, 14 Aug 2017 08:50:39 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:d0fba842-b0bd-4203-ad12-56f641c951d0</guid><dc:creator>Tom  Hofste</dc:creator><description>Thank you for the code improvement.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change the identity when adding a user</title><link>https://www.aras.com/community/thread/752?ContentTypeID=1</link><pubDate>Sun, 13 Aug 2017 05:07:19 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:9dcc4dcf-3644-4565-95a3-2fb004a1b006</guid><dc:creator>Zahar Chernov</dc:creator><description>Happy to hear that my solution helped you.

You can simplify you code:

Instead (3 lines of code):
&lt;blockquote&gt;Item userItem = this.newItem(&amp;quot;User&amp;quot;,&amp;quot;get&amp;quot;);
userItem.setProperty(&amp;quot;id&amp;quot;,userId);
userItem = userItem.apply();&lt;/blockquote&gt;
You can use (one line of code):
&lt;blockquote&gt;Item userItem = this.getInnovator().getItemById(&amp;quot;User&amp;quot;, userId);&lt;/blockquote&gt;
Instead creating if statement (5 lines of code), you can write something like (one line) :
&lt;blockquote&gt;updateIdnt.setProperty(&amp;quot;name&amp;quot;, userItem.getProperty(&amp;quot;{prop1}&amp;quot;, &amp;quot;&amp;quot;) + ( (!string.IsNullOrEmpty(userItem.getProperty(&amp;quot;{prop2}&amp;quot;))) ? &amp;quot; &amp;quot; + userItem.getProperty(&amp;quot;{prop2}&amp;quot;) + &amp;quot; &amp;quot; : &amp;quot;&amp;quot;)  + userItem.getProperty(&amp;quot;{prop3}&amp;quot;,&amp;quot;&amp;quot;));&lt;/blockquote&gt;
If you prefer to keep the if statement, you need to update it as following:
&lt;blockquote&gt;if (string.IsNullOrEmpty(userItem.getProperty(&amp;quot;{prop2}&amp;quot;))&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change the identity when adding a user</title><link>https://www.aras.com/community/thread/746?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2017 10:37:43 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:aaf98b49-4a41-4aa9-ad3e-1b6204dca63e</guid><dc:creator>Tom  Hofste</dc:creator><description>Hello Zahar,

Thank you for your suggestion.
I wasn&amp;#39;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.
&lt;pre&gt;&lt;code&gt;
Innovator inn = this.getInnovator();

Item identItm =this.getPropertyItem(&amp;quot;related_id&amp;quot;);
string userId = this.getProperty(&amp;quot;source_id&amp;quot;);

Item userItem = this.newItem(&amp;quot;User&amp;quot;,&amp;quot;get&amp;quot;);
userItem.setProperty(&amp;quot;id&amp;quot;,userId);
userItem = userItem.apply();

Item updateIdnt = this.getInnovator().newItem(&amp;quot;Identity&amp;quot;, &amp;quot;merge&amp;quot;);
updateIdnt.setID(identItm.getID());
if (userItem.getProperty(&amp;quot;{prop2}&amp;quot;,&amp;quot;&amp;quot;) == null) 
{
    updateIdnt.setProperty(&amp;quot;name&amp;quot;, userItem.getProperty(&amp;quot;{prop1}&amp;quot;, &amp;quot;&amp;quot;) + &amp;quot; &amp;quot; + userItem.getProperty(&amp;quot;{prop3}&amp;quot;,&amp;quot;&amp;quot;));   
} else
{
    updateIdnt.setProperty(&amp;quot;name&amp;quot;, userItem.getProperty(&amp;quot;{prop1}&amp;quot;, &amp;quot;&amp;quot;) + &amp;quot; &amp;quot; + userItem.getProperty(&amp;quot;{prop2}&amp;quot;,&amp;quot;&amp;quot;) + &amp;quot; &amp;quot; + userItem.getProperty(&amp;quot;{prop3}&amp;quot;,&amp;quot;&amp;quot;));
}
updateIdnt.apply();

return inn.newResult(&amp;quot;&amp;quot;);&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change the identity when adding a user</title><link>https://www.aras.com/community/thread/667?ContentTypeID=1</link><pubDate>Thu, 20 Jul 2017 15:28:16 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:5c9d5be8-2894-4f00-9b92-2c4e72eb1817</guid><dc:creator>Zahar Chernov</dc:creator><description>Hello Tom,

If I understand it right, you want to be able to set Identity name to different value than &amp;quot;First Name &amp;amp; Last Name&amp;quot;?

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:
&lt;blockquote&gt;Item userItm = this.getPropertyItem(&amp;quot;source_id&amp;quot;);
Item identItm =this.getPropertyItem(&amp;quot;related_id&amp;quot;);

Item updateIdnt = this.getInnovator().newItem(identItm.getType(), &amp;quot;merge&amp;quot;);
updateIdnt.setID(identItm.getID());
updateIdnt.setProperty(&amp;quot;name&amp;quot;, userItm.getProperty(&amp;quot;{prop1}&amp;quot;, &amp;quot;&amp;quot;) + &amp;quot; &amp;quot; + userItm.getProperty(&amp;quot;{prop2}&amp;quot;) + &amp;quot; &amp;quot; + userItm.getProperty(&amp;quot;{prop3}&amp;quot;));
updateIdnt.apply();&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>