Providing user information in JSON
In the MUSE project we encountered the need to retrieve user information in JSON format. Easy done one would think. The trouble starts, when you have multiple directories and you need reasonable speed. Sometimes falling back to @Fomulas gives you what you need, fast and easy.
The form makes extensive use of
As usual YMMV
@NameLookup
knows where to look and you don't need any extra configuration. A simple call to an form will give you all you need:
for yourself or add &User=John Doe
for any other user. This will return:
{
"QueryName": "John Doe",
"NotesName": "CN=John Doe/OU=ThePitt/O=GIJoe",
"AllNames": [
"CN=John Doe/OU=ThePitt/O=GIJoe",
"john.doe@thepitt.com",
"John Doe/ThePitt/GIJoe",
"John Doe",
"john.doe"
],
"eMail": "john.doe@thepitt.com",
"MailDomain": "SACMEA",
"MailServer": "CN=PittServer42/OU=ThePitt/O=GIJoe",
"MailFile": "mail/jdoe.NSF",
"Empnum": "0815",
"Empcc": "4711"
}
The form makes extensive use of
@NameLookup
and looks in DXL quite simple.You can just copy the body into your database.
<form name='NameLookup'>
<body>
<richtext>
<pardef id='1'>
<code event='hidewhen'>
<formula>@True</formula>
</code>
</pardef>
<pardef id='2' />
<par def='1'>
<run>
<font color='red' />
<field type='text' kind='computedfordisplay' name='dUser'>
<code event='defaultvalue'>
<formula>
tmp := @Trim(@UrlQueryString("user"));
@If(@IsError(tmp)|tmp="";@UserName;tmp)
</formula>
</code>
</field>
<field type='text' allowmultivalues='true' kind='computedfordisplay' name='dMailFile'>
<code event='defaultvalue'>
<formula>@MailDbName</formula>
</code>
</field>
<field type='text' allowmultivalues='true' kind='computedfordisplay' name='dFullName'>
<code event='defaultvalue'>
<formula>@NameLookup([Exhaustive];dUser;"FullName")</formula>
</code>
</field>
</run>
</par>
<par def='2'>{</par>
<par def='2'>
"QueryName" : "
<field type='text' kind='computedfordisplay' name='duser3'>
<code event='defaultvalue'>
<formula>dUser</formula>
</code>
</field>
",
</par>
<par def='2'>
"NotesName" : "
<field type='text' kind='computedfordisplay' name='dUser2'>
<code event='defaultvalue'>
<formula>@Subset(dFullName;1)</formula>
</code>
</field>
",
</par>
<par def='2'>
"AllNames" : ["
<field type='text' kind='computedfordisplay' name='dUser4'>
<code event='defaultvalue'>
<formula>
stage1 := dFullName:@NameLookup([Exhaustive];dUser;"ShortName");
stage2 := @Name([Abbreviate];stage1);
stage3 := @Name([CN];stage1);
@Implode(@Trim(@Unique(stage1:stage2:stage3));"\", \"")
</formula>
</code>
</field>
"],
</par>
<par def='2'>
"eMail" : "
<field type='text' kind='computedfordisplay' name='dEmail'>
<code event='defaultvalue'>
<formula>@Trim(@Unique(@NameLookup([Exhaustive];dUser;"InternetAddress")))</formula>
</code>
</field>
",
</par>
<par def='2'>
"MailDomain" : "
<field type='text' kind='computedfordisplay' name='dDomain'>
<code event='defaultvalue'>
<formula>@Trim(@Unique(@NameLookup([Exhaustive];dUser;"MailDomain")))</formula>
</code>
</field>
",
</par>
<par def='2'>
"MailServer" : "
<field type='text' kind='computedfordisplay' name='dServer'>
<code event='defaultvalue'>
<formula>@Trim(@Unique(@NameLookup([Exhaustive];dUser;"MailServer")))</formula>
</code>
</field>
",
</par>
<par def='2'>
"MailFile" : "
<field type='text' kind='computedfordisplay' name='dFile'>
<code event='defaultvalue'>
<formula>@ReplaceSubstring(@Trim(@Unique(@NameLookup([Exhaustive];dUser;"MailFile")));"\\";"/")</formula>
</code>
</field>
",
</par>
<par def='2'>
"Empnum" : "
<field type='text' kind='computedfordisplay' name='dEmpnum'>
<code event='defaultvalue'>
<formula>@Trim(@Unique(@NameLookup([Exhaustive];dUser;"Empnum")))</formula>
</code>
</field>
",
</par>
<par def='2'>
"Empcc" : "
<field type='text' kind='computedfordisplay' name='dEmpcc'>
<code event='defaultvalue'>
<formula>@Trim(@Unique(@NameLookup([Exhaustive];dUser;"Empcc")))</formula>
</code>
</field>
"
</par>
<par def='2'>}</par>
</richtext>
</body>
<item name='$MimeType'>
<text>application/json</text>
</item>
<item name='$$ScriptName' summary='false' sign='true'>
<text>namelookup</text>
</item>
</form>
As usual YMMV
Posted by Stephan H Wissel on 20 November 2014 | Comments (1) | categories: IBM - Lotus IBM Notes XPages