1

I am using the following code to dynamically execute calls to a table method that may or may not be present.

However, it always returns Error executing code: myTableName table does not have method 'myUpdateMethod'.

    Dicttable         dictTable;
    Common            common;
    ExecutePermission perm;

    perm = new ExecutePermission();
    dictTable= new DictTable(tableName2Id('myTableName'));
    if (dictTable != null)
    {
        common = dictTable.makeRecord();

        // Grants permission to execute the
        // DictTable.callObject method. DictTable.callObject runs
        // under code access security.
        perm.assert();
        dictTable.callObject('myUpdateMethod', common);
    }

    // Close the code access permission scope.
    CodeAccessPermission::revertAssert();

These objects are in different models, but just for kicks I tried making a reference between the two models to see if it made a difference. It did not fix the issue.

Thanks

AnthonyBlake
  • 2,334
  • 1
  • 25
  • 39
Brad
  • 1,357
  • 5
  • 33
  • 65
  • Has your method arguments? You does not specify additional parameters in callobject(). Therefore it lookup myUpdateMethod() without parameters. --- Advises: 1. Use SysDictTable instead Dict Table 2. Use SysDictTable.isMethodActual() to check method presense 3. Don't use string for object names - It lose cross references. Use tablenum(myTablename) instead tableName2Id('myTableName') and use methodstr(myUpdateMethod) instead 'myUpdateMethod'. – mazzy Nov 21 '17 at 15:50

1 Answers1

1

Changed the method being called from static to non-static.

Started working, then found the callStatic() equivalent.

Here is the code I ended up using for the non-static method, which has no params.

    Dicttable         dictTable;
    Common            common;
    ExecutePermission perm;

    perm = new ExecutePermission();
    dictTable= new DictTable(tableName2Id('MyTableName'));
    if (dictTable != null)
    {
        common = dictTable.makeRecord();
        // Grants permissions
        perm.assert();
        if (dictTable.doesMethodExist('myMethodName'))
        {
            dictTable.callObject('myMethodName', common);
        }
    }

    // Close the code access permission scope.
    CodeAccessPermission::revertAssert();
Brad
  • 1,357
  • 5
  • 33
  • 65
  • 1
    Its always good two verify the method exists before executing same. Please use tableHasMethod method in global class for same. For static method verification there is tableHasStaticMethod method. – Pradeep Muttikulangara Vasu Nov 20 '17 at 18:12