{"id":806,"date":"2012-08-23T14:26:41","date_gmt":"2012-08-23T12:26:41","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=806"},"modified":"2012-08-23T17:30:14","modified_gmt":"2012-08-23T15:30:14","slug":"quick-n-dirty-clienttype-in-xpages","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=806","title":{"rendered":"Quick-n-Dirty: @ClientType() in XPages"},"content":{"rendered":"<p>The <em>@ClientType<\/em> formula provides an interesting behaviour: If you add the value to a label, the result will be as expected. It returns \u201c<em>Web<\/em>\u201d in Browser and returns \u201c<em>Notes<\/em>\u201d in XPiNC.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;xp:view xmlns:xp=\"http:\/\/www.ibm.com\/xsp\/core\"&gt;\r\n   &lt;xp:label value=\"#{javascript:@ClientType()}\" id=\"label1\" \/&gt;\r\n&lt;\/xp:view&gt;<\/pre>\n<p>But if you add it to a computed field on a form and use this form in a datasource, the result in XPiNC is not &#8222;<em>Notes<\/em>&#8222;, it is &#8222;<em>None<\/em>&#8220; instead. In the following example, the form &#8222;<em>Test<\/em>&#8220; has a computed field named &#8222;<em>ClientType<\/em>&#8222;. The value of the field is <em>@ClientType<\/em>.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;xp:view xmlns:xp=\"http:\/\/www.ibm.com\/xsp\/core\"&gt;\r\n\r\n   &lt;xp:this.data&gt;\r\n\u00a0\u00a0    &lt;xp:dominoDocument var=\"document1\" formName=\"Test\" \r\n         computeWithForm=\"onload\"&gt;\r\n\u00a0\u00a0 \u00a0  &lt;\/xp:dominoDocument&gt;\r\n   &lt;\/xp:this.data&gt;\r\n\r\n\u00a0\u00a0 &lt;xp:label value=\"#{javascript:@ClientType()}\" id=\"label1\" \/&gt;\r\n\u00a0\u00a0 &lt;xp:br \/&gt;\r\n\u00a0\u00a0 &lt;xp:label id=\"label2\"&gt;\r\n\u00a0\u00a0    &lt;xp:this.value&gt;\r\n\u00a0\u00a0 \u00a0\u00a0    &lt;![CDATA[#{javascript:\r\n            document1.getItemValueString(\"ClientType\")\r\n         }]]&gt;\r\n\u00a0\u00a0 \u00a0 &lt;\/xp:this.value&gt;\r\n   &lt;\/xp:label&gt;\r\n&lt;\/xp:view&gt;<\/pre>\n<p>[The <em>computeWithForm<\/em> property of the datasource has to be set to &#8222;<em>onload<\/em>&#8220; or &#8222;<em>onsave<\/em>&#8222;. If set to &#8222;<em>onboth<\/em>&#8220; this will not work.]<\/p>\n<p>This behaviour gives you control about the subforms which are used in the form, depending of the client and\/or technology. Just add a computed subform to your form and add a @Formula like this:<\/p>\n<pre>@If(\r\n\u00a0\u00a0 \u00a0@ClientType=\"Web\";\"WebAccess\";\r\n\u00a0\u00a0 \u00a0@ClientType=\"Notes\";\"NotesAccess\";\r\n\u00a0\u00a0\u00a0 \"XPiNCAccess\"\r\n)<\/pre>\n<p>This allows you to add specific fields to a document, or can help to identify the way how the document was created. If you add a field in the <em>querySave<\/em> event on the XPage, you can identify if this document was created in the web by XPage or old-school web access of the form.<\/p>\n<pre>&lt;xp:this.data&gt;\r\n   &lt;xp:dominoDocument var=\"document1\" formName=\"Test\"\r\n\u00a0\u00a0    computeWithForm=\"onsave\"&gt;\r\n      &lt;xp:this.querySaveDocument&gt;\r\n\u00a0\u00a0 \u00a0\u00a0    &lt;![CDATA[#{javascript:\r\n            document1.replaceItemValue(\"ClientTypeXPage\", \"1\"))\r\n         }]]&gt;\r\n\u00a0\u00a0 \u00a0\u00a0 &lt;\/xp:this.querySaveDocument&gt;\r\n\u00a0\u00a0 &lt;\/xp:dominoDocument&gt;\r\n&lt;\/xp:this.data&gt;<\/pre>\n<p>By extending the subform computation, you can use a subform for every type of access:<\/p>\n<pre>@If(\r\n\u00a0\u00a0 \u00a0@ClientType=\"Web\" &amp; ClientTypeXPage=\"1\";\"XPageWebAccess\";\r\n\u00a0\u00a0 \u00a0@ClientType=\"Web\";\"WebAccess\";\r\n\u00a0\u00a0 \u00a0@ClientType=\"Notes\";\"NotesAccess\";\r\n\u00a0\u00a0\u00a0 \"XPiNCAccess\"\r\n)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The @ClientType formula provides an interesting behaviour: If you add the value to a label, the result will be as expected. It returns \u201cWeb\u201d in Browser and returns \u201cNotes\u201d in XPiNC. &lt;?xml version=&#8220;1.0&#8243; encoding=&#8220;UTF-8&#8243;?&gt; &lt;xp:view xmlns:xp=&#8220;http:\/\/www.ibm.com\/xsp\/core&#8220;&gt; &lt;xp:label value=&#8220;#{javascript:@ClientType()}&#8220; id=&#8220;label1&#8243; \/&gt; &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=806\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,1,76,81,74],"tags":[93,7,5,32,12,3],"class_list":["post-806","post","type-post","status-publish","format-standard","hentry","category-formula","category-allgemein","category-ssjs","category-web","category-xpages","tag-formula","tag-domino","tag-ssjs","tag-tipp","tag-web","tag-xpages"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=806"}],"version-history":[{"count":11,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/806\/revisions"}],"predecessor-version":[{"id":816,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/806\/revisions\/816"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}