{"id":777,"date":"2012-08-05T21:09:10","date_gmt":"2012-08-05T19:09:10","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=777"},"modified":"2012-08-05T21:09:10","modified_gmt":"2012-08-05T19:09:10","slug":"xpages-access-a-datasource-from-one-custom-control-in-another-one","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=777","title":{"rendered":"XPages: Access a datasource from one custom control in another one"},"content":{"rendered":"<p>On <a href=\"http:\/\/stackoverflow.com\/\" target=\"_blank\">stackoverflow.com<\/a>,\u00a0a very interesting question was asked: How can you access a document datasource from one custom control in another custom control. And here comes my solution in a small SSJS function.<\/p>\n<p>First you have to add an id to the custom control which contains the datasource. This gives you a handle for other custom controls:<\/p>\n<pre>&lt;xc:ccDS1 <strong>id=\"idDSComponent\"<\/strong>&gt;&lt;\/xc:ccDS1&gt;<\/pre>\n<p>Now it is possible to get the custom control by using the SSJS function <em>getComponent()<\/em>. The datasources are stored in the data attribute of the custom control. You just have to iterate through them and check every entry for the name you are looking for.<\/p>\n<p>And here is the code snippet to access the datasource in another custom control:<\/p>\n<pre>\/***\r\n * getDatasource\r\n * Resolves a datasource from a custom control\r\n\u00a0* \r\n\u00a0* @param componentId\u00a0\u00a0 \u00a0id of the component containing the datasource\r\n\u00a0* @param dsName\u00a0\u00a0 \u00a0name of the datasource in the component\r\n\u00a0* @author Sven Hasselbach\r\n\u00a0*\/\r\n\u00a0function getDatasource( componentId:String, dataSourceName:String ):com.ibm.xsp.model.domino.DominoDocumentData {\r\n\u00a0   try{\r\n\u00a0\u00a0 \u00a0   var data:java.util.ArrayList = getComponent( componentId ).getAttributes().get(\"data\");\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 if( data == null )\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0    return null;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 var it:java.util.Iterator = data.iterator();\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 var obj = null;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 while( it.hasNext() ){\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0    obj = it.next();\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0 if( obj.getVar() == dataSourceName )\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0    return obj;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0 \u00a0}catch(e){\r\n\u00a0\u00a0 \u00a0   print( e );\r\n\u00a0\u00a0 \u00a0}\r\n}<\/pre>\n<p>To use the function you have to use it like this:<\/p>\n<pre>getDatasource( \"idDSComponent\", \"document1\" )<\/pre>\n<p>Here is the link to the original question: <a href=\"http:\/\/stackoverflow.com\/questions\/11802196\/how-to-get-document-datasource-in-another-custom-control\">How to get document datasource in another Custom Control?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>On stackoverflow.com,\u00a0a very interesting question was asked: How can you access a document datasource from one custom control in another custom control. And here comes my solution in a small SSJS function. First you have to add an id to &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=777\">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":[9,76,74],"tags":[33,7,5,32,3],"class_list":["post-777","post","type-post","status-publish","format-standard","hentry","category-javascript","category-ssjs","category-xpages","tag-8-5-3","tag-domino","tag-ssjs","tag-tipp","tag-xpages"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/777","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=777"}],"version-history":[{"count":8,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/777\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/777\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}