CosmosDB icon indicating copy to clipboard operation
CosmosDB copied to clipboard

UDF does not store unless escaped

Open BrianVallelunga opened this issue 1 year ago • 1 comments

Issue

  • [x] PowerShell 7.2.7
  • [x] Host: VS Code terminal
  • [x] Windows 11
  • [x] 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
'@

BrianVallelunga avatar Nov 30 '22 21:11 BrianVallelunga

Refreshment

konvict25 avatar Jan 02 '24 10:01 konvict25