Custom formula with generic parameters

Posted by: thais.sumiyoshi on 27 November 2023, 2:59 pm EST

  • Posted 27 November 2023, 2:59 pm EST

    I have a custom formula that receives n parameters (arrays), for example I can receive a single column of salaries (C2:C18), or several columns of salaries (C2:C11;D2:D11;E2:E11;F2:F11). I need a way to receive this as only one parameter, which contains all the columns, (an array of arrays), or a way to indicate what type of information the parameter is, since I don’t know the number of parameters that will be passed.

  • Posted 28 November 2023, 2:21 am EST - Updated 28 November 2023, 3:00 am EST

    Hi,

    You can use the arguments keyword to get all the available parameters in the function. Please refer to the following code snippet and let me know if you face any issues.

     MyCustomFunction.prototype.evaluate = function (arg) {
                console.log(arguments);
            };

    Regards,

    Avinash

  • Posted 29 November 2023, 7:49 am EST

    I found a way to do it using just a big array and identifying the lines by the number of columns I receive from the formula.

    Now I have another problem. Is there a way to send comparisons in the custom formula? I’m selecting a range in a column, and I want to compare each line to another cell value, so I would like to send <=Cell or Cell or >=Cell.

    I’m dealing with a date filter now.

    exemple: customFormula(someDataToDoMath;B:B;<=B2)

    where Column B will be where I want to search, and <=B2 my filter date. When I try to do this, it says that the formula is invalid.

  • Posted 30 November 2023, 12:38 am EST

    Hi,

    This is expected if you want to pass the opertor in the custom you should pass it as a string and parse it in your custom function. Please refer to the following example and let me know if you face any issues.

    //second argument is the source where to want to search the third argument would be the operator and the fourth argument would be the value of the operand.
     customFormula(someDataToDoMath;B:B,"<=",B2)

    Regards,

    Avinash

  • Posted 27 December 2023, 9:08 am EST

    That one worked!

    Now I’m facing a different problem with the custom formula. I don’t have any set for calculation mode, therefor it should update the formula result when I alter a value from a cell that is being used by the formula, right?

    It only changes when I copy and past a value into the cell I want to change the value. When I type the value, the formula is not called again to update itself.

    What I noticed as well is that, when I have at first a number(I receive a number format in my code) in a cell and I change to another number in that same cell, it changes the format to string, and even if I try to change the format to number, it keeps as a string.

  • Posted 28 December 2023, 6:53 am EST

    Hi,

    I was unable to understand the issue and your requirement. Could you kindly elaborate the issue you are facing with an example so that we could have a better understanding of your use case and could assist you accordingly?

    It would be helpful if you could share a sample with the issue and the steps to reproduce the issue. Also, kindly share your expected result and your use case.

    As a starting point, you could fork the following sample that implements a custom function. You could modify the sample below with your implementation and the issue you are facing.

    Sample: https://jscodemine.grapecity.com/share/0pNIaYTivEGH9ZCPsoYbNQ/?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"}

    Regards,

    Ankit

Need extra support?

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

Learn More

Forum Channels