Generate Calculation Script
/ai/applications/{applicationName}/databases/{databaseName}/calculation/generate
Generates the calculation script.
Request
-
applicationName(required):
Application name.
-
databaseName(required):
Database name.
Response
200 Response
OK
Calculation script generated successfully.
400 Response
Bad Request
Failed to generate calculation script.
Examples
The following examples shows how to generate a calculation script using AI. For the first conversation, the request body must include the user prompt with conversation_count set to 0. For all subsequent requests, the request must include the conversation_id and conversation_count returned in the previous response in addition to the new user prompt.
This example uses cURL to access the REST API from a Windows shell script. The calling user's ID and password are variables whose values are set in properties.bat.
Example
Generating the first conversation.
Script with cURL Command
call properties.bat
curl -X 'POST' \
'http://myserver.example.com.com:9000/essbase/rest/v1/ai/applications/sample/databases/basic/calculation/generate' \
-H 'accept: */*' \
-H 'Content-Type: */*' \
-u %User%:%Password% \
-d '{
"user_prompt": "Assign 1000 to Budget for Christmas month.",
"conversation_count": 0
}'
Example of Response Body
{
"script": "FIX(\"Dec\")\n\"Budget\" = 1000;\nENDFIX\n",
"response": "The given Essbase calculation script assigns the value 1000 to the \"Budget\" member
specifically for the \"Dec\" (December) member. Here's a step-by-step breakdown:\n- The
`FIX(\"Dec\")` statement sets the scope of the calculation to the \"Dec\" member, meaning
the operation within this block will only apply to data related to December.\n- `\"Budget\"
= 1000;` assigns the value 1000 to the \"Budget\" member within the fixed scope (i.e., for
December).\n- `ENDFIX` marks the end of the FIX statement, closing the scope set for
\"Dec\".\nIn summary, this script is used to set the budget for December to
1000.",
"nearest_neighbour": "{\"Budget\":[{\"KEY\":\"Budget\",\"MEM_NAME\":\"Budget\",\"DIM_NAME\":\"Scenario\"}],
\"Christmas\":[{\"SCORE\":0.4130075888813005,\"MEM_NAME\":\"Dec\",\"DIM_NAME\":\"Year\",
\"KEY\":\"Dec\"}]}",
"conversation_id": "57971B41-CA50-F7DC-E063-4F424664F391",
"conversation_count": 1
}
Example 2
Generating a subsequent conversation.
Script with cURL Command
call properties.bat
curl -X 'POST' \
'http://myserver.example.com:9000/essbase/rest/v1/ai/applications/sample/databases/basic/calculation/generate' \
-H 'accept: */*' \
-H 'Content-Type: */*' \
-u %User%:%Password% \
-d '{
"user_prompt": "Copy data from Actual to Budget for children of East.",
"conversation_id": "48E1061C-5FF6-A3BB-E063-67935E6495DF",
"conversation_count": 1
}'
Example of Response Body
{
"script": "FIX(@CHILDREN(\"East\"))\nDATACOPY \"Actual\" TO \"Budget\";\nENDFIX\n",
"response": "The given Essbase calculation script copies data from the \"Actual\" member to the
\"Budget\" member for all children of the \"East\" member. It uses a FIX statement
to limit the scope to the children of \"East\" and the DATACOPY command to perform the data transfer.",
"nearest_neighbour": "{\"Actual\":[{\"KEY\":\"Actual\",\"MEM_NAME\":\"Actual\",\"DIM_NAME\":\"Scenario\"}],
\"Budget\":[{\"KEY\":\"Budget\",\"MEM_NAME\":\"Budget\",\"DIM_NAME\":\"Scenario\"}],
\"East\":[{\"KEY\":\"East\",\"MEM_NAME\":\"East\",\"DIM_NAME\":\"Market\"}]}",
"conversation_id": "57971B41-CA50-F7DC-E063-4F424664F391",
"conversation_count": 2
}