Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDF does not store unless escaped #464

Open
4 tasks done
BrianVallelunga opened this issue Nov 30, 2022 · 1 comment
Open
4 tasks done

UDF does not store unless escaped #464

BrianVallelunga opened this issue Nov 30, 2022 · 1 comment

Comments

@BrianVallelunga
Copy link

BrianVallelunga commented Nov 30, 2022

Issue

  • PowerShell 7.2.7
  • Host: VS Code terminal
  • Windows 11
  • CosmosDB Module: 4.6.0

This UDF example does not work:

$body = @'
function tax(income) {
    if(income == undefined) throw 'no input';
    if (income < 1000)
        return income * 0.2;
    else if (income < 10000)
        return income * 0.3;
    else
        return income * 0.4;
}
'@
Set-CosmosDbUserDefinedFunction -Context $cosmosDbContext -CollectionId 'MyNewCollection' -Id 'udfTax' -Body $body

It seems as though the body is not escaped properly when being created. As a result, the function does not show up correctly. If I JSON encode the function body, then it will work properly.

$body = @'
function tax(income) {\r    if(income == undefined) throw 'no input';\r    if (income < 1000)\r        return income * 0.2;\r    else if (income < 10000)\r        return income * 0.3;\r    else\r        return income * 0.4;\r}\r
'@
@konvict25
Copy link

Refreshment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants