{"action":"created","issue":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4785","labels_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4785/labels{/name}","comments_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4785/comments","events_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4785/events","html_url":"https://github.com/orientechnologies/orientdb/issues/4785","id":100695598,"number":4785,"title":"\"No such function\" error occurred while creating & executing Javascript Functions dynamically.","user":{"login":"randikaf","id":12937387,"avatar_url":"https://avatars.githubusercontent.com/u/12937387?v=3","gravatar_id":"","url":"https://api.github.com/users/randikaf","html_url":"https://github.com/randikaf","followers_url":"https://api.github.com/users/randikaf/followers","following_url":"https://api.github.com/users/randikaf/following{/other_user}","gists_url":"https://api.github.com/users/randikaf/gists{/gist_id}","starred_url":"https://api.github.com/users/randikaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randikaf/subscriptions","organizations_url":"https://api.github.com/users/randikaf/orgs","repos_url":"https://api.github.com/users/randikaf/repos","events_url":"https://api.github.com/users/randikaf/events{/privacy}","received_events_url":"https://api.github.com/users/randikaf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-13T05:52:51Z","updated_at":"2015-09-21T17:21:24Z","closed_at":"2015-09-21T17:21:24Z","body":"I have encountered with below error while creating Javascript functions and executing it from a web application. The newly created function is not getting executed and below error has been occurred.\r\n\r\n    Exception in thread \"main\" com.orientechnologies.orient.core.command.script.OCommandScriptException: Error on parsing script at position #0: Error on execution of the script\r\n    Script: testFunction3\r\n    ------^\r\n    \tat com.orientechnologies.orient.core.command.script.OCommandExecutorFunction.executeInContext(OCommandExecutorFunction.java:106)\r\n    \tat com.orientechnologies.orient.core.metadata.function.OFunction.executeInContext(OFunction.java:148)\r\n    \tat com.orientechnologies.orient.core.metadata.function.OFunction.execute(OFunction.java:123)\r\n    \tat Test.main(Test.java:45)\r\n    Caused by: java.lang.NoSuchMethodException: No such function testFunction3\r\n    \tat jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:190)\r\n    \tat jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:505)\r\n    \tat jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:227)\r\n    \tat com.orientechnologies.orient.core.command.script.OCommandExecutorFunction.executeInContext(OCommandExecutorFunction.java:93)\r\n    \t... 3 more\r\n\r\n\r\nThis issue can recreate using below code snippet and using below mentioned steps. Here I used this code to simulate the function execution happen in my web application. Web application initialize the DB connection at startup.\r\n\r\n\t\tODatabaseDocumentTx db = new ODatabaseDocumentTx(\"remote:localhost/SampleDb\");\r\n\t\tdb.open(\"admin\", \"admin\");\r\n\t\tboolean enableNextFunc = false;\r\n\t\tfinal String functionName = \"testFunction\";\r\n\t\tString name = functionName +\"1\";\r\n\t\tint count = 1;\r\n\t\twhile (true) {\r\n\t\t\tdb.reload();\r\n\t\t\t\r\n\t\t\tif(enableNextFunc){\r\n\t\t\t\tname = functionName+count;\r\n\t\t\t}\r\n\t\t\tOFunction sum = db.getMetadata().getFunctionLibrary().getFunction(name);\r\n\r\n\t\t\t\r\n\t\t\tif(sum != null){\r\n\t\t\t\tMap<String, Object> params = new HashMap<String, Object>();\r\n\t\t\t\tparams.put(\"a\", \"160:9\");\r\n\t\t\t\t//\r\n\t\t\t\tObject obj = (Object) sum.execute(\"160:9\");\r\n\t\t\t\tSystem.out.println(\"Function: \"+functionName +\", Result: \"+obj.toString());\r\n\t\t\t\ttry {\r\n\t\t\t\t\tThread.currentThread().sleep(1000);\r\n\t\t\t\t} catch (InterruptedException e) {\r\n\t\t\t\t\t// TODO Auto-generated catch block\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t\tcount++;\r\n\t\t\t\tenableNextFunc= true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n - Run the above code in a main method.\r\n - Create a Javascript function from the Orientdb Studio with the name of `testFunction1` and with a simple `return \"F1\";` script & save.\r\n - Then again create another function with the name of `testFunction2` with the script of `return \"F2\";`\r\n\r\nThe function `testFunction1` will execute but the second function `testFunction2` will not execute and will throw the above error.\r\n"},"comment":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/comments/142048217","html_url":"https://github.com/orientechnologies/orientdb/issues/4785#issuecomment-142048217","issue_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/4785","id":142048217,"user":{"login":"lvca","id":312606,"avatar_url":"https://avatars.githubusercontent.com/u/312606?v=3","gravatar_id":"","url":"https://api.github.com/users/lvca","html_url":"https://github.com/lvca","followers_url":"https://api.github.com/users/lvca/followers","following_url":"https://api.github.com/users/lvca/following{/other_user}","gists_url":"https://api.github.com/users/lvca/gists{/gist_id}","starred_url":"https://api.github.com/users/lvca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lvca/subscriptions","organizations_url":"https://api.github.com/users/lvca/orgs","repos_url":"https://api.github.com/users/lvca/repos","events_url":"https://api.github.com/users/lvca/events{/privacy}","received_events_url":"https://api.github.com/users/lvca/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T17:21:24Z","updated_at":"2015-09-21T17:21:24Z","body":"By reading your log, the error is on \"testFunction3\" that doesn't exist in the database. In your description you speak about testFunction1 and testFunction2, but not testFunction3 that is the function not found."}}