how to store function with parameters?

%3CLINGO-SUB%20id%3D%22lingo-sub-650639%22%20slang%3D%22en-US%22%3Ehow%20to%20store%20function%20with%20parameters%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-650639%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20define%20a%20function%20with%20parameters.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fquery%2Ffunctions%2Fuser-defined-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fquery%2Ffunctions%2Fuser-defined-functions%3C%2FA%3E%26nbsp%3Bstates%20there%20are%20two%20type%20of%20functions%3A%3C%2FP%3E%3CP%3Ead-hoc%3C%2FP%3E%3CP%3EStored%20functions%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20create%20a%20ad-hoc%20function%20with%20no%20problem%2C%20but%20I%20can't%20save%20it%20as%20stored%20function.%3C%2FP%3E%3CP%3EFor%20example%2C%20ad-hoc%20function%20works%3A%3C%2FP%3E%3CPRE%3Elet%20MyAdd%20%3D%20(x%3Along%20%2C%20y%3Along)%20%7B%3CBR%20%2F%3Eprint%20x%20%2B%20y%3CBR%20%2F%3E%7D%3B%3CBR%20%2F%3EMyAdd(%201%2C2)%3C%2FPRE%3E%3CDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EBut%20when%20I%20save%20it%20as%20a%20function%2C%20I%20want%20to%20save%20it%20as%26nbsp%3B%3C%2FP%3E%3CPRE%3Elet%20MyAdd%20%3D%20(x%3Along%20%2C%20y%3Along)%20%7B%3CBR%20%2F%3Eprint%20x%20%2B%20y%3CBR%20%2F%3E%7D%3B%3C%2FPRE%3E%3CP%3EThen%20I%20can%20call%20it%20with%20different%20x%20and%20y%2C%20but%20when%20I%20tried%20to%20save%20it%2C%20I%20got%20error%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%22Cannot%20save%20an%20empty%20function%2C%20please%20select%20a%20query%20in%20the%20editor.%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ENot%20sure%20what%20I%20am%20missing%20here.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fmanagement%2Ffunctions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fmanagement%2Ffunctions%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Esuggested%20I%20can%20use%20%22.show%20function%22%20and%20%22.create%20function%22%20%2C%20but%20none%20of%20them%20works%20%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20819px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F116196i754F710724D353DC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-650639%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuery%20Language%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-964117%22%20slang%3D%22en-US%22%3ERe%3A%20how%20to%20store%20function%20with%20parameters%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-964117%22%20slang%3D%22en-US%22%3E%3CP%3EHas%20anybody%20every%20figured%20this%20out%3F%26nbsp%3B%20I'm%20currently%20running%20into%20the%20same%20issue.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1079943%22%20slang%3D%22en-US%22%3ERe%3A%20how%20to%20store%20function%20with%20parameters%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1079943%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F435855%22%20target%3D%22_blank%22%3E%40JPPage%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F349580%22%20target%3D%22_blank%22%3E%40Jack_Chen%3C%2FA%3E%20Not%20sure%20if%20you%20got%20this%20figured%20out%20already.%20I%20find%20that%20when%20saving%20a%20function%20you%20have%20to%20put%20the%20cursor%20on%20the%20function%20name%20in%20the%20editor%20first%20(presumably%20because%20there%20may%20be%20several%20functions%20defined%20there%20and%20it%20wants%20to%20know%20which%20one%20you%20are%20trying%20to%20save).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20still%20have%20problem%20with%20calling%20the%20query%20I%20just%20saved.%20It%20takes%20a%20little%20bit%20of%20time%20to%20show%20up%20under%20the%20%22functions%22%20tree%20item%20(and%20can%20later%20be%20managed%20in%20the%20Saved%20Queries%20section%20-%20e.g.%20deleted)%20but%20whenever%20I%20try%20to%20use%20it%20in%20another%20query%20I%20get%20an%20error%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EBody%20of%20the%20callable%20expression%20cannot%20be%20empty%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20anybody%20knows%20how%20to%20fix%20that%20please%20reply.%20Thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Visitor

I am trying to define a function with parameters.

 

https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions states there are two type of functions:

ad-hoc

Stored functions

 

I can create a ad-hoc function with no problem, but I can't save it as stored function.

For example, ad-hoc function works:

let MyAdd = (x:long , y:long) {
print x + y
};
MyAdd( 1,2)
 

But when I save it as a function, I want to save it as 

let MyAdd = (x:long , y:long) {
print x + y
};

Then I can call it with different x and y, but when I tried to save it, I got error:

"Cannot save an empty function, please select a query in the editor."

 

Not sure what I am missing here.

 

https://docs.microsoft.com/en-us/azure/kusto/management/functions

suggested I can use ".show function" and ".create function" , but none of them works :

 

image.png

 

 

 

 

 

 

2 Replies
Highlighted

Has anybody every figured this out?  I'm currently running into the same issue.

Highlighted

@JPPage @Jack_Chen Not sure if you got this figured out already. I find that when saving a function you have to put the cursor on the function name in the editor first (presumably because there may be several functions defined there and it wants to know which one you are trying to save).

 

I do still have problem with calling the query I just saved. It takes a little bit of time to show up under the "functions" tree item (and can later be managed in the Saved Queries section - e.g. deleted) but whenever I try to use it in another query I get an error:

 

Body of the callable expression cannot be empty

 

If anybody knows how to fix that please reply. Thanks!