Custom function execution context sheet

Posted by: n.serrette on 22 September 2022, 8:01 pm EST

    • Post Options:
    • Link

    Posted 22 September 2022, 8:01 pm EST

    Hi,

    I am trying to create a custom function which need to be aware of its execution context.

    By using isContextSensitive and returning true I can get a context object during the evaluation which contains de cell coordinates.

    However, in my case I also need the sheet or at least a mean to find it (name or index).

    For the moment the only way I could think of was adding a field to my function with the sheet name and adding the function to each worksheet.

    Ideally I would like to be able to instantiate the function once on the workbook level and getting the sheet from the context.

    Is their a proper way to do it?

    Regards.

  • Posted 25 September 2022, 11:22 pm EST

    Hi,

    We are sorry but for a custom function, the contexct is not exposed you use the custom async function for getting the context of the evaluation. The first argument on evaluate method(on AsyncFunction Class) is nothing but the object of context.

    Please refer to the following code snippet:

    
      asum.prototype.evaluateAsync = function ([b]context[/b], arg) {
          // do evaluate on server to get result ...
            fetch("data").then(function(response){
                context.setAsyncResult(response.text());
            })
        };
    
    

    Regards,

    Avinash

  • Posted 26 September 2022, 12:27 am EST

    Is their any hope to see an execution context publicly exposed in the future, containing at least the reference (worksheet, col, row) of the executed function?

  • Posted 27 September 2022, 9:53 pm EST

    Hi,

    We have made an enhancement request on your behalf. We will update you regarding this as soon as we get any information from the team. The internal ID for this issue will be SJS-14911.

    Regards,

    Avinash

  • Posted 28 September 2022, 1:52 am EST

    Thank you

  • Posted 29 September 2022, 3:17 pm EST

    Hi,

    The team infromed us that When implementing the custom function, the customer could overwrite the isContextSensitive, and return true.

    Then, the context will be the first args of the evaluate function.

    API: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.CalcEngine.Functions.Function#iscontextsensitive

    Regards,

    Avinash

  • Posted 29 September 2022, 6:23 pm EST

    Hi,

    Thank you for your answer,

    Is it possible to have an interface describing the context object?

    I noticed that the object are different between the AsyncFunction and the Function.

    The AsyncFunction seems to encapsulate the Function context.

    Regards,

  • Posted 5 October 2022, 4:10 pm EST

    HI,

    We are sorry but the evaluateContext is not a public type.

    basically, you could get

    row - the function evaluation row.

    column - the function evaluate column.

    sheet - arguments[0].source.getSheet(), the function evaluate sheet.

    regards,

    Avinash

  • Posted 5 October 2022, 6:02 pm EST - Updated 5 October 2022, 6:03 pm EST

    Hi,

    Thank for your reply.

    Regards

Need extra support?

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

Learn More

Forum Channels