Calling server method from another server method

オフライン

Hello All,

From one server method (Method A ), I'm calling another server method (Method B) .

From (Method B) returning inn.newError("Error"); 

And in calling method (Method A) checking result has error but it is not working. Error message is showing directly on UI.

Item X = inn.applyMethod("Method_B","");

if(X.isError())

{

//execute xlogic

else

{

  //execute y logic

}

But if case is not executing & error message directly displaying on UI.

Regards,

Suhas

  • Hi Suhas,

    The applyMethod function will cause a client-side error dialog to show up.  You'll want to use the inn.apply() function instead.

    Try replacing the line "Item X = etc." from Method A with

    Item X = inn.newItem("Method", "Method_B");
    X = X.apply();

    This should make everything else work as is.

    -Kate

  • Hi there,

    you can also just use any method as the apply()-action on any item. Consequently, that item would be "this" in the called method.

    I.e.

    var methodResult = someItem.apply("Method B");

    Hope this helps,

    C

    EDIT: Just to clear up the confusion with applyMethod(): The second input parameter to applyMethod() is supposed to be a string representation of the dom of the Item you want to be "this" in the method. Hence your approach results in an error, you passed an empty method item.
    From the API description:

    Parameters
      methodName
       Name of the method.
      body
       Context for the method (method item).
    Remarks
    The context for the method will be the method item, in the form: <Item type="Method" action="{methodName}">{body}</Item> Note, that only methods that use IOM namespace from .NET (C#, VBScript) can be applied, and methods written in JavaScript cannot be applied.
  • 0 オフライン in reply to Kate Marsh

    Hello Kate,

    How to pass parameter(argument) to Method_B? with the help of setProperty()?

    Regards,

    Suhas

  • Hi Suhas,

    see my reply below. You can pass any information from Method A to Method B by setting properties on the item you apply the method on:

    // we have an Innovator object called inn
    var methodItem = inn.newItem("Method");
    methodItem.setProperty("some_info_for_method_b", "value for that info");
    var resultItem = methodItem.apply("Method B");

    You can then access some_info_for_method_b in Method B with

    string info = this.getProperty("some_info_for_method_b", "")

    Of course, you can set as many of those auxiliary properties as you like, or pass all method arguments in one property, separated by commas.

    Hope this helps,

    C

  • 0 オフライン in reply to cogres

    Hello Cogres,

    Thanks for the update. It is working fine.

    Regards,

    Suhas