"Uncaught Cannot change part of an array" error when using .setFormula

Posted by: tyler.franklin on 2 April 2024, 2:23 am EST

  • Posted 2 April 2024, 2:23 am EST

    Good morning,

    Do you have any insight on what normally causes the “Uncaught Cannot change part of an array” error message to be displayed.

    I am receiving the error when trying to use the .setFormula method on a sheet that has been unprotected and a cell that has been unlocked.

  • Posted 2 April 2024, 8:07 am EST - Updated 2 April 2024, 8:16 am EST

    Here is some more context to my problem. I have figured out that there is a change in my formulas before and after a named range is added that spans the cells in which my formulas are contained. I used the sheet.getFormulaInformation() function to gather the following data.

    See the following image file named FormulaInformationBeforeNamedRangeIsAdded.

    This is what sheet.getFormulaInformation() returns before I add a named range that spans the cells that contain my formulas. See following image.



    The following image named FormulaInformationAfterNamedRangeIsAdded is what sheet.getFormulaInformation() returns after I add the named range.

    Something in the process of adding the named range is changing the .isArrayFormula property of my formulas. This is causing the formulas to be treated as array formulas which is why I receive the aforementioned “Cannot change part of an array” error when I try to use sheet.setFormula(). See following image.



    Do you know why created a named range over existing formulas changes the .isArrayFormula property?

  • Posted 2 April 2024, 4:47 pm EST - Updated 2 April 2024, 4:52 pm EST

    Hi,

    I could see that the isArrayFormula property changes in the screenshots that you have shared.

    Based on the information provided, I tried to replicate the issue, however, I was unsuccessful. At my end, when creating a named range, the “isArrayFormula” property remains same.

    You could refer to the attached gif that shows the steps I have followed on the below sample.

    Sample: https://jscodemine.mescius.io/share/X9KDWLPn5k_uGMLR1iJ45g/?IsEmbed=false&Theme=Unset&PreviewDirection=0&IsEditorShow=true&IsExplorerShow=true&IsPreviewShow=true&IsConsoleShow=true&IsRunBTNShow=false&IsResetBTNShow=false&IsOpenInCodemineBTNShow=false&PanelWidth=20&PanelWidth=50&PanelWidth=30&defaultOpen={"OpenedFileName"%3A["%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    Could you kindly share us a minimal working sample replicating the issue? Also, kindly mention the steps you are following. A video/gif showing the issue would be helpful. You may modify the above sample also and share it with us replicating the issue.

    Regards,

    Ankit

  • Posted 3 April 2024, 5:31 am EST

    Good afternoon,

    See attached for the sjs file that I am using. Please use the attached sjs file, and perform the same steps that you performed in the gif above.

    My issue does not only occur when I add a named range. It also now occurs when I edit any named range.

    sanitizedTemplate.zip

  • Posted 3 April 2024, 11:27 pm EST - Updated 3 April 2024, 11:32 pm EST

    Hi,

    Thanks for sharing the “.sjs” file with us. I tried with the above sample and the file that you have shared. However, I was unable to reproduce the issue.

    You could refer to the attached gif that shows the steps I have performed.

    Could you kindly share the video/gif showing the steps using the above sample? Also, kindly do share the steps where you are getting the mentioned error “Uncaught Cannot change part of an array”.

    Regards,

    Ankit

  • Posted 12 April 2024, 1:36 pm EST

    Good evening Ankit,

    Please refer to the first video file titled “1. Formula Corresponds to Row Index and Is Not Array Formula”. This video shows that the formula in row 29 of the Rates sheet corresponds to the row it is in, and is not an array formula.

    Please refer to the second video file titled “2. No Error Occurs While Switching Sheets”. This video shows that I can switch from the Rates sheet to the WBS sheet without an error.

    Please refer to the third video file titled “3. Upload Sjs Template and Save Changes”. This videos shows the only two changes that I make to the template after I upload the template to the designer at https://developer.mescius.com/spreadjs/designer/index.html. Also, it shows the settings checks when I upload and download the sjs file.

    Please refer to the fourth video titled “4. Received Error Uncaught Cannot change part of an array”. This file shows that the formula in row 29 on the Rates sheet is now referring to row 24, and that the formula is now an array formula. Also, it shows that when I navigate to the WBS sheet I receive an error. No changes have been made to the code base. The only change is in the sjs file.

    I have attached the sjs file before I save it when an error does not occur and after I save it from designer and an error does occur. Is it possible that some type of workbook or sheet setting changes that I am unaware of? For instance, refer to the following post where the dev team pointed out I was using an invalid pageRange setting in printInfo() for my WBS sheet.

    I apologize for some of the videos being quick. I had to keep them short to keep the file size below 5MB.

    1. Formula Corresponds to Row Index and Is Not Array Formula.zip

  • Posted 12 April 2024, 1:36 pm EST

    Here are the other video files. 2. No Error Occurs While Switching Sheets.zip

  • Posted 12 April 2024, 1:37 pm EST

  • Posted 12 April 2024, 1:37 pm EST

  • Posted 12 April 2024, 1:42 pm EST

    Please send me a way to directly send you the sjs files before and after they are saved. I would prefer to not have the sjs files posted on a public forum.

  • Posted 15 April 2024, 2:40 pm EST

    Hi Tyler,

    I have created a case for you on our private portal. You could view the case by visiting https://developer.mescius.com/my-account/my-support.

    The ticket id for the same is: CAS-48825-F4X3T3. You could share the sjs file with us on our private portal.

    Do let me know if you face any issues while accessing the case.

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels