Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a sheet in Smartsheet using Java API

I am trying to use the Smartsheet API 2.0 in java to copy an existing sheet to a new sheet in an existing folder. I would like to include the data, attachments and discussions. I have tried setting the include parameter to SheetCopyInclusion.ALL as well as SheetCopyInclusion.DATA, SheetCopyInclusion.ATTACHMENTS and SheetCopyInclusion.DISCUSSIONS. The sheet copies, but never the data.

Here is my code:

Token token = new Token();
token.setAccessToken( accessToken );

Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken( token.getAccessToken() ).build();

ContainerDestination myCopiedSheet = new ContainerDestination.AddContainerDestinationBuilder()
    .setDestinationType( DestinationType.FOLDER )
    .setDestinationId( backupFolderId )
    .setNewName( "My Copied Sheet" )
    .build();

smartsheet.sheetResources().copySheet( sourceSheetId, myCopiedSheet, EnumSet.of( SheetCopyInclusion.ALL ));

Any assistance on why the data is not being copied would be appreciated. Thank you.

like image 627
T R Avatar asked Jun 13 '26 00:06

T R


1 Answers

T R, this is an issue with the SheetCopyInclusion enumeration. Rather than 'return super.toString();' the toString function in SheetCopyInclusion should return the inclusion String. If you are building the SDK from source, you can modify toString in SheetCopyInclusion.java:

@Override
public String toString() {
    return inclusion;
    //return super.toString();
}

I will submit a pull request to the JAVA SDK with a fix.

like image 178
timwells Avatar answered Jun 14 '26 15:06

timwells



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!