microsoft / microsoft/Power-Fx

ReflectionFunction FormulaType Blank issue

Open
#2,897 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.4k
Forks
358
Avg merge
10h 34m
Merged PRs (30d)
3

Description

Hi,

I'm having issue with running my formula on a custom function, it seems it always wants an object and when the object is null / blank it just throws error: {Error: Runtime type mismatch}, is there a way to fix this without adding a check in the formula?

function:
`public class HasTermGuidFunction : ReflectionFunction
{
public HasTermGuidFunction()
: base("HasTermGuid", FormulaType.Boolean, [RecordType.Empty(), FormulaType.String]) { }

public static BooleanValue Execute(FormulaValue t, StringValue s)
{
    if (t is RecordValue recordValue)
    {
        // Parse the input string to handle comma-separated values
        var searchTerms = s.Value.Split([',', ';', ' '], StringSplitOptions.RemoveEmptyEntries)
            .Select(g => g.Trim())
            .ToList();

        // If no specific terms provided, use "*" as wildcard
        if (searchTerms.Count == 0)
        {
            searchTerms.Add("*");
        }

        // Use "all" as the default matching mode
        return FormulaValue.New(HasTermGuidImplementation.HasTermMatchRecursive(recordValue, searchTerms, "all"));
    }

    return FormulaValue.New(false);
}

}`

Formula:
"If(Not(HasTermGuid(NewPage.Properties.BusinessArea,defaultDepartment)),defaultDepartment)",

If NewPage.Properties.BusinessArea is an object it works fine
If NewPage.Properties.BusinessArea is Blank / Blank() ({N}) it throws {Error: Runtime type mismatch}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing ReflectionFunction and the FormulaType.RecordType.Empty() argument handling for the shown HasTermGuid formula. Reproduce the Runtime type mismatch with a blank NewPage.Properties.BusinessArea, then compare it with the object case. Done means the blank input behavior is resolved without requiring a formula-side check, with coverage for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.