Search code examples
ibm-sbt

How do I programmatically add a tag to a file uploaded to a community on IBM SmartCloud?


I am uploading the file using the IBM Social Business Toolkit and now want to add tag(s) to it. Either as part of the upload or immediately afterwards. In the javadocs I can see that the FileService has a method to add a comment to a file. I can't see an equivalent for Tags though.


Solution

  • There is a Java method to update a tag on a community file - but it is broken in the most recent version of Smartcloud. It has actually been fixed in the most recent GitHub version of the code but it is not available for download as of April 2015.

    The bug is reported here https://github.com/OpenNTF/SocialSDK/issues/1624. The method SHOULD be updateCommunityFileMetadata and with that we could add TAGs as Metadata. That would be simple to add to the end of the "addFile" Java method.

    The sample code to TAG a file can be found here in the playgroup - it is updating the Meta Data via JavaScript API

    https://greenhouse.lotus.com/sbt/sbtplayground.nsf/JavaScriptSnippets.xsp#snippet=Social_Files_API_UpdateCommunityFileMetadata

    to TAG a file use the following

    function tagFile(yourFileId, yourDocUnid){
        require([ "sbt/connections/FileService", "sbt/dom", "sbt/json" ], function(FileService, dom, json) {
    
            var fileService = new FileService();
            var fileId = yourFileId
            var docId = yourDocUnid
            var tagArray = [];
            tagArray.push(docId)
    
            fileService.updateCommunityFileMetadata({
                id: fileId,
                tags: tagArray
            }, communityId).then(function(file) {
                dom.setText("json", json.jsonBeanStringify(file));
            }, function(error) {
                dom.setText("json", json.jsonBeanStringify(error));
            });
    
        });
    }