Menu

Table Script Validator not working?

Developers
Jairah
2009-11-27
2014-04-29
  • Jairah

    Jairah - 2009-11-27

    Hello everyone! :)

    I made this **Rule**:

    Search Key: beanshell:AD\_Rule\_Before_New

    Name: AD_Rule Before New

    Event Type: Model Validator Table Event

    Rule Type: JSR 223 Scripting APIs

    Script:

        if (G_Ctx.AD_Role_Name == "QA")
           result = "QA is not allowed to create new data.";
        else
           result = "";

    In my **Table Script Validator**:

    Event Model Validator: Table Before New

    Rule: AD_Rule Before New

    My problem now is, there's no error, no syntax error, but nothing is happening. I even tried to replace **result** to **return and remove equal (=) sign** but nothing happens.

    What should I do or put to make it work?

    Thanks!

    Jairah :)

     
  • Redhuan D. Oon

    Redhuan D. Oon - 2009-11-27

    Hi Jairah,
    Why don't you try to test a dummy script sample first?
    Just to proof the concept on TableScriptValidator if it really works in the first place.

    red1

     
  • Jairah

    Jairah - 2009-11-27

    Hello Red :)

    Yes, I've tried this  and it worked.

      : http://www.adempiere.com/index.php/Script_ModelValidator

    I guess it's the code that's wrong that's why nothing seems to be happening.

    Is this the right way for calling AD_Role_Name?

    > if (G\_Ctx.AD\_Role_Name == "QA")

    Thanks! :)

    Jairah

     
  • Redhuan D. Oon

    Redhuan D. Oon - 2009-11-28

    Great, you got one proof right, now to this script you trying out: -
    Theoretically i would first proof that script next. I would do that by making it display itself. That means i would make result = G_Ctx.AD_Role_Name. Try it. I like to know if it works also.

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-11-28

    Jairah, I have not tested, but please can you test this different construction for your code:

        if (G_Ctx.AD_Role_Name == "QA")
           tmp = "QA is not allowed to create new data.";
        else
           tmp = "";
        result = tmp;

    Regards,

    Carlos Ruiz

     
  • Jairah

    Jairah - 2009-11-30

    **Hi Carlos and Red, :)**

    Sorry for the late reply, had some problems with my machine, now it's fixed… :)

    I've tried what you've suggested Carlos and it produced an error:

    <pre>
    <code>
    javax.script.ScriptException: Sourced file: inline evaluation of:
    ``if (G_Ctx.AD_Role_Name == "QA") tmp = "QA is not allowed to create new data." . . . '' :
    Class or variable not found: G_Ctx.AD_Role_Name : at Line: 1 : in file: inline evaluation of:
    ``if (G_Ctx.AD_Role_Name == "QA") tmp = "QA is not allowed to create new data." . . . '' :
    G_Ctx .AD_Role_Name

    in inline evaluation of:
    ``if (G_Ctx.AD_Role_Name == "QA") tmp = "QA is not allowed to create new data." . . . '' at line number 1
    </code>
    </pre>

    And when I tried what Red suggested, here's what happened (error):

    <pre>
    <code>
    javax.script.ScriptException: Sourced file: inline evaluation of: ``A_PO.setDescription(G_Ctx.AD_Role_Name); result = "";'' : Class or variable not found: G_Ctx.AD_Role_Name : at Line: 1 : in file: inline evaluation of: ``A_PO.setDescription(G_Ctx.AD_Role_Name); result = "";'' : G_Ctx .AD_Role_Name
    in inline evaluation of: ``A_PO.setDescription(G_Ctx.AD_Role_Name); result = "";'' at line number 1
    </code>
    </pre>

    So, I guess the problem is in **G\_Ctx.AD\_Role\_Name** right? So, what should I use?

    **Thanks! :)**

    **Jairah**

     
  • Akos Gabriel

    Akos Gabriel - 2009-11-30

    Hi Jairah,

    Did you run the client from Eclipse? If yes, then you can see at the "eval" what environment your script has. I haven't tested your script but I have two ideas:

    1. G_Ctx is not loaded into the environment
    2. G_Ctx is there but doesn't have AD\_Role\_Name attribute

    If you ran your client from within Eclipse you could check (around the "eval") the environment. Right there you can see what exactly you have and what is callable there.

    Regards,

    Akos

     
  • Jairah

    Jairah - 2009-12-01

    Hi Akos! :)

    Where can i look for that "eval"? Console of eclipse? but it's not there…

    Thanks! :)

    Jairah

     
  • Jairah

    Jairah - 2009-12-01

    Hi Everyone! :)

    I tried it this way…

        if (G_AD_Role_Name == "QA")
            tmp = "QA is not allowed to create new data.";
        else
            tmp = "";
        result = tmp;

    but, nothing happens.. it still saves… i tried to make sure if G\_AD\_Role\_Name is working, so I made it this way…

        A_PO.setDescription(G_AD_Role_Name);
        result="";

    And this one works…

    I don't get it…

    Thanks!

    Jairah :)

     
  • Akos Gabriel

    Akos Gabriel - 2009-12-01

    Hi,

    We have all overlooked that, it's so obvious…
    You cannot compare strings that way in Java.

    use:

    <pre><code>
    if (G_AD_Role_Name.equals("QA"))
    </code></pre>

    By using '==' you would compare pointers which are (almost) never equal.

    Regards,

    Akos

    PS: I hate markdown syntax so much.

     
  • Jairah

    Jairah - 2009-12-02

    Hello Akos,

    Still not working… >_< but thanks for the code anyway.

    Jairah :)

     
  • Jairah

    Jairah - 2009-12-02

    This is what I tried…

        if (G_AD_Role_Name.equals("QA")){
          tmp = "QA is not allowed to create new data.";
        }else{
          tmp = "";
        }

        result = tmp;

    Same error occurred…

        Sourced file: inline evaluation of: ``if (G_AD_Role_Name.equals("QA")){ tmp = "QA is not allowed to create new data . . . '' : Class or variable not found: A_PO.Name : at Line: 4 : in file: inline evaluation of: ``if (G_AD_Role_Name.equals("QA")){ tmp = "QA is not allowed to create new data . . . '' : A_PO .Name

    Still trying to find where it went wrong, thanks guys! :)

    Jairah :)

     
  • Jairah

    Jairah - 2009-12-02

    **Hello Everyone! :D**

    it's working now…

        if (G_AD_Role_Name.equals("QA"))
           tmp = "QA is not allowed to create new data.";
        else
           tmp = "";
       
        result = tmp;

    **Thanks Akos, Carlos, and Red! :D**

    Jairah :D

     
  • Akos Gabriel

    Akos Gabriel - 2009-12-02

    Hi Jairah,

    I don't see the difference, apart from the {} -s (which shouldn't make any difference).

    Regards,

    Akos

     
  • uTIC_Seveter

    uTIC_Seveter - 2014-04-29

    Hi everyone,

    sorry for my english
    if you used {}, you have to declared first the variable tmp
    Ej.
    Integer tmp= new Integer(10);
    if (G_AD_Role_Name.equals("QA"))
    {
    tmp = "QA is not allowed to create new data.";
    }
    else
    {
    tmp = "";
    }
    result = tmp;

    Regards

     

Log in to post a comment.