Creating and Formatting Sheet Summary Field with API using Python

Options

I am updating a handful of sheet summaries using Python. My current code creates the sheet summary fields that I want with the correct formulas however I am unable to get the formatting to work properly. Below is a partial screenshot of the code: 

According to the API docs I should be able to set the formatting of the sheet summary value since 'format' is part of the SummaryField objects.

I did create the object currenctFormat (line 6) which is set to be USD with zero decimal places ($0). I have also tried not using the currencyFormat object and putting the format string directly in the code (line 22). While the code runs and I have no errors, the formatting is the default (0) and not what I am trying to set it to ($0). Below are screenshots of my run log as well as the newly created sheet summary field:


Note: in the above screenshot ‘Current Week – Value of Jobs WON’ was previously created manually

Answers

  • Julio S.
    Julio S. Moderator
    Options

    Hi @Garrett Henke,

    On the API documentation about Formatting there is a note that asks to return the the FormatTables object to be able to identify the default settings and what are the formatting options available. This is advised because the formatting can change at any time. 

    In further research, I found a similar issue was experienced by other Smartsheet user when formatting cells in the Smartsheet app and was able to resolve with the following methods: GET ROW (before cell format update); UPDATE ROW (cell format); GET ROW (after cell format update). In this case you may try with Get Summary Fields; Update Summary Fields; Get Summary Fields from the Sheet Summary method listYou can review this post for your reference on the reported problem with applying currency formats to cells that seemed to resolve the matter. 

    I hope this can offer some guidance. 

    Cheers! 

    Julio

  • Garrett Henke
    Garrett Henke ✭✭✭✭✭
    Options

    @Julio S. I have tried the above and the formatting is still not showing correct within the sheet summary.

  • Julio S.
    Julio S. Moderator
    Options

    Hi @Garrett Henke,

    I can see you've also opened a ticket with our Support team where you've been referred to Stack Overflow which I'd also recommend as the best resource for API and coding questions.

    If returning the FormatTables doesn't seem to fully work as a solution, I'd recommend following up on your case with Support and adding some screenshots of your current code trying to return the FormatTables and applying them. Please note that although Support won't be able to write code for you, they will most certainly be able to troubleshoot any API call or error you may see.

    Cheers!

    Julio

  • Alex Argumedo
    Alex Argumedo ✭✭✭✭
    Options

    I know the question is one year old, but to provide a proper answer:

    Try adding the formatting to each field:

                summ_fld = ss.models.SummaryField()

                summ_fld.format = ",,,,,,,,,,,,,1,2,,"

                summ_fld.type = 'TEXT_NUMBER'

                summ_fld.title = 'Contract amount'

                summ_fld.value = 0