Forum Stats

  • 3,733,811 Users
  • 2,246,823 Discussions
  • 7,856,882 Comments

Discussions

Problems while using a custom functions

712796
712796 Member Posts: 20
Dear OPA team,

I am having some difficulties using a custom functions.
1. I have created a custom function class (.net).
2. I have created a configuration file named "rtb-config.xml" (rtb.zip is the rule base file). I placed the file in the project's output folder.
*3. When I run the OPA engine (in process) in a C# application I am getting the following exception when creating the session object:*
*"Exception returning CustomFunctionHandler: Library file… doesn't exist".*
4. When I load the function via code the engine doesn't throw any exception.
*5. When I embed the custom function in a Word document as in the following example:*
I have a custom function that generates a student's registration number. When I am writing in the Word document the following phrase:
The student's is registration number = GenerateRegistrationNumber()*
The compiler (rule's compiler) displays an error message "Error after … Found: = GenerateRegistrationNumber()'. Expected…".
*5. When I push the Build and Debug button in the OPM UI I gets the following error message:*
*"Exception returning CustomFunctionHandler: Library file… doesn't exist".*

Please help,
Doron B.M
Tagged:

Answers

  • Davin Fifield-Oracle
    Davin Fifield-Oracle Member, Moderator Posts: 1,032 Employee
    Have you declared the student's is registration number as a variable with the appropriate type?
  • 712796
    712796 Member Posts: 20
    edited January 2010
    I have managed to work around the engine custom function dll file loading issue.
    It seems that the 'library-path' parameter in the configuration couldn't handle a absolute path that is defined as 'c:\test\func'. Hence I used a relative path and the engine loaded the custom function dll with no problem.

    But the main issue remains:
    How do I get the APM compiler to recognize the custom function's name?
    As I mentioned in my last post, when I write and compile the following:
    The student's registration number = GenerateRegistrationNumber()I am getting the following compiler error:
    *"Error after The student's registration number'. Found: = GenerateRegistrationNumber()'. Expected expression, variable, constant ".*
    This implies that the compiler doesn't recognize the 'GenerateRegistrationNumber' function.

    What is the correct way to make the compiler recognize custom functions?


    Cheers,
    Doron

    Edited by: Doron on 02:11 05/01/2010
  • Davin Fifield-Oracle
    Davin Fifield-Oracle Member, Moderator Posts: 1,032 Employee
    This compiler error usually happens when the variable being assigned to has not been declared with the appropriate type.

    In this case, the "student's registration number" needs to be declared as a number or text attribute, either in the properties file, or in the document itself.
  • Davin Fifield-Oracle
    Davin Fifield-Oracle Member, Moderator Posts: 1,032 Employee
    Two other things to try:
    (1) Try using the CallCustomFunction( ) approach instead of directly calling the function
    (2) Make sure you have the <rulebasename>-config.xml file setup in the <project>/output directory to refer to your custom function handler.
  • 712796
    712796 Member Posts: 20
    I changed the syntax to:
    The student's registration number = Number(callcustomfunction("GenerateRegistrationNumber","")
    and it worked!

    Thanks.
This discussion has been closed.