javasmartsheet-apismartsheet-java-sdk-v2

Smartsheet Java API Getting Discussions


Trying to programmatically get comments made on rows in smartsheet with the Java API. When I use row.getDiscussions() it always returns null even though comments are present on that row.

try 
{
    Smartsheet CommericalSmartsheet = new SmartsheetBuilder().setAccessToken("*****************").build();
    Sheet sheet = CommericalSmartsheet.sheetResources().getSheet(*************,null,null,null,null,null,null,null);
    List<Row> rows = sheet.getRows();
    System.out.println("Number of Rows:  " + rows.size());
    for(int x = 0;  x<rows.size();x++)
    {
        System.out.println("Row #:  " + x);
        List<Discussion> discussions = rows.get(x).getDiscussions();
        if (discussions != null)
        {
            System.out.println("Number of Discussions:  " + rows.get(x).getDiscussions().size());
            for(int y=0;y<discussions.size();y++)
            {
                List<Comment> comments = discussions.get(y).getComments();
                for (int i=0;i<comments.size();i++)
                {
                    String CommentText = comments.get(i).getText();
                    User createdBy = comments.get(i).getCreatedBy();
                    Date createdAt = comments.get(i).getCreatedAt();
                    System.out.println(createdBy.toString() + " " + createdAt.toString() + ":  " + CommentText);
                 }
            }
        }
    }
} catch (SmartsheetException ex) {
            Logger.getLogger(TFSpush.class.getName()).log(Level.SEVERE, null, ex);
        }

My output is

Number of Rows:  1026
Row #:  0
Row #:  1
Row #:  2
Row #:  3
Row #:  4
Row #:  5
Row #:  6
Row #:  7
Row #:  8
Row #:  9
Row #:  10
Row #:  11
Row #:  12
Row #:  13
Row #:  14

I won't bore you with the rest just counts to 1026


Solution

  • Please try using SheetInclusion.DISCUSSIONS as you are getting the sheet:

    Set<SheetInclusion> inclusionSet = Collections.singleton(SheetInclusion.DISCUSSIONS);
    Sheet sheet = CommericalSmartsheet.sheetResources().getSheet(*************,inclusionSet,null,null,null,null,null,null);
    

    For more information, see the SheetResources.getSheet() method, and the SheetInclusion Enum in the SDK doc.