Menu

Script CallOut

Developers
Shiju01
2009-07-30
2013-04-29
1 2 > >> (Page 1 of 2)
  • Shiju01

    Shiju01 - 2009-07-30

    What is the code for beanshell script callout  from a column DISCOUNT

    in tab C_ORDERLINE can check the C_DOCTYPE_ID=1000025 ?

    when C_DOCTYPE_ID is a column in tab C_ORDER

     
    • salientvijay

      salientvijay - 2009-07-31

      Hi shiju!
      Please use the foloowing code to check your condition

      Integer order_id = (Integer) mTab.getValue("C_ORDER_ID");
              MOrder obj = new MOrder(Env.getCtx(),order_id.intValue(),null);
              if(obj.getC_DocType_ID()==1000025 )
      {
      your code....
      }

      if you phase any problem please let me know...

      Thanks & Regards
      Vijay

       
    • Shiju01

      Shiju01 - 2009-08-02

      Hi

      It shows an error as follows

      Typed variable declaration : Attempt to resolve method: getValue() on undefined variable or class name: mTab : at Line: 3 : in file: inline evaluation of:
      mTab .getValue ( "C_ORDER_ID" )

      So i changed mTab to A_Tab

      After that next error shows
      Typed variable declaration : Class: MOrder not found in namespace : at Line: 4 : in file: inline evaluation of: ``import java.math.BigDecimal; BigDecimal

      What to do next ?

       
    • Shiju01

      Shiju01 - 2009-08-02

      I have explored MORDER.JAVA, MORDERLINE.JAVA and MORDERTAX.JAVA and finaly had
      it cobled like this

      package org.compiere.model;

      import java.math.BigDecimal;
      import java.util.Properties;

      import org.adempiere.exceptions.AdempiereException;
      import org.compiere.util.Env;
      import org.compiere.util.Msg;

      BigDecimal PriceList,BasePrice,ChannelDiscPerc,ChannelDiscAmt;
      Integer X_Doc_ID=(Integer)A_Tab.getValue("C_Order_ID");
      MOrder quote=new MOrder(Env.getCtx(),X_Doc_ID.intValue(),null);
      if (quote.getC_DocType_ID()==1000027)
      {PriceList = new java.math.BigDecimal(0.00);
      BasePrice = new java.math.BigDecimal(0.00);
      ChannelDiscPerc = new java.math.BigDecimal(0.00);
      ChannelDiscAmt = new java.math.BigDecimal(0.00);
      if (A_Tab.getValue("PriceList") != null)
      {PriceList = (BigDecimal)A_Tab.getValue("PriceList");}
      if (A_Tab.getValue("ChannelDiscount") != null)
      {ChannelDiscPerc = (BigDecimal)A_Tab.getValue("ChannelDiscount");}
      ChannelDiscAmt = new BigDecimal ((PriceList.doubleValue() * ChannelDiscPerc.doubleValue()) / 100.00);
      A_Tab.setValue("ChannelDiscountAmt", ChannelDiscAmt );
      BasePrice=new BigDecimal (PriceList.doubleValue() - ChannelDiscAmt.doubleValue());
      A_Tab.setValue("BasePrice", BasePrice);}
      result = "";

      This a beanshell script callout

      a) Can you do some clean up (ref. not realy required.) ?
      b) Please explain this code and what is ENV & getCtx()
          MOrder quote=new MOrder(Env.getCtx(),X_Doc_ID.intValue(),null);

      Payment Terms: 100% Thanks in Advance & Balance 100% on Delivery!!!

       
    • Shiju01

      Shiju01 - 2009-08-04

      What is wrong with this Script Callout ?
      No Error... But not updating the Prodcut Description from M_PRODUCT table

      package org.compiere.model;

      import java.lang.*;
      import java.util.*;
      import java.util.Properties;
      import java.util.logging.Level;
      import java.sql.*;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Timestamp;
      import java.math.*;  
      import java.math.BigDecimal;
      import java.io.Serializable;  

      import org.adempiere.exceptions.AdempiereException;
      import org.compiere.util.*;  
      import org.compiere.model.*;
      import org.compiere.util.CLogger;
      import org.compiere.util.DB;
      import org.compiere.util.DisplayType;
      import org.compiere.util.Env;
      import org.compiere.util.Ini;
      import org.compiere.util.Msg;

      Integer X_ItCode;
      Integer X_Doc_ID=(Integer)A_Tab.getValue("C_Order_ID");
      MOrder quote = new MOrder(Env.getCtx(),X_Doc_ID.intValue(),null);
      if (quote.getC_DocType_ID()!=1000027)
      {

      X_ItCode = (Integer)(0);
      if (A_Tab.getValue("M_Product_ID") != null)
          {
          Integer X_ItCode = (Integer)A_Tab.getValue("M_Product_ID");
          }

      String sql= "Select prod.Description from M_Product prod where prod.M_Product_ID=?";
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try
          {
          pstmt = DB.prepareStatement(sql, null);
          pstmt.setInt(1, X_ItCode.intValue());
          rs = pstmt.executeQuery();
          if (rs.next())
          { A_Tab.setValue( "Description", rs.getString(1) ); }
          }
      catch (SQLException e)
          {
          log.log(Level.SEVERE, sql, e);
          return e.getLocalizedMessage();
          }
      finally
          {
          DB.close(rs, pstmt);
          rs = null; pstmt = null;
          }
      }
      result = "";

       
      • Carlos Ruiz

        Carlos Ruiz - 2009-08-04

        Hi Shiju, which is the condition to execute the callout, I suppose on creation of the order the callout the C_Order_ID is zero.

        Debugging script callouts is very hard, so my advice would be to add some log.log or System.out.println to your code to see what's happening inside (old way of debug).

        Also, all the SQL code can be replaced with just one line like:

        String description = DB.getSQLValueString ....

        Regards,

        Carlos Ruiz

         
    • Shiju01

      Shiju01 - 2009-08-05

      Hi Mr. Carlos, Thank you ... I will try that.

       
    • Duonh Diem

      Duonh Diem - 2009-08-05

      Hii Shiju!!!
      You need replace Integer X_ItCode = (Integer)A_Tab.getValue("M_Product_ID"); 
      with
      X_ItCode = (Integer)A_Tab.getValue("M_Product_ID");
      Good Luck!!!

       
    • Shiju01

      Shiju01 - 2009-08-08

      Wants Product Description to be automatically filled after selecting Product Id in Order Line

      But Something is wrong somewhere! requires more brains

      Integer X_ItCode = null;
      if (A_Tab.getValue("M_Product_ID") != null) 
      {
      X_ItCode = (Integer)A_Tab.getValue("M_Product_ID");
      }
      String sql= "Select Description from M_Product where M_Product_ID=?";
      String X_ItDesc = DB.getSQLValueString( null, sql, X_ItCode);
      A_Tab.setValue( "Description", X_ItDesc );
      result = "";

       
      • Colin Rooney

        Colin Rooney - 2009-08-08

        I think you are over complicating things!
        in the CalloutOrder look for ...

        if (Env.isSOTrx(ctx, WindowNo))
                {
                    MProduct product = MProduct.get (ctx, M_Product_ID.intValue());
        and below it add
                    mTab.setValue("Description", product.getDescription());
        because of the isSOTrx this would only work for SO but even so the existing
        >>> MProduct product = MProduct.get (ctx, M_Product_ID.intValue());
        Should show you how to get a product rather than writing SQL!

        colin

         
      • Carlos Ruiz

        Carlos Ruiz - 2009-08-08

        Hi Shiju, this code worked for me:

        Integer X_ItCode = (Integer)A_Tab.getValue("M_Product_ID");
        if (X_ItCode == null)
            X_ItCode = Integer.valueOf(0);
        System.out.println("X_ItCode="+X_ItCode);
        String sql= "Select Description from M_Product where M_Product_ID=?";
        String X_ItDesc = org.compiere.util.DB.getSQLValueString( null, sql, X_ItCode.intValue());
        A_Tab.setValue( "Description", X_ItDesc );
        result = "";

        --------------

        I created the Rule with value="beanshell:fillDescription"
        And filled the callout on C_OrderLine.M_Product_ID with "org.compiere.model.CalloutOrder.product;@script:beanshell:fillDescription"

        There are lots of things to improve to such callout, for example as Colin advised using model class to get the product, or avoiding to execute the query when the product is not filled, etc.

        Regards,

        Carlos Ruiz - globalqss
        http://globalqss.com

         
        • Colin Rooney

          Colin Rooney - 2009-08-09

          > I created the Rule with value="beanshell:fillDescription"
          Aha... a beanshell based Rule.  I had missed that bit in the discussion.

          colin

           
        • Yogi Sugianto

          Yogi Sugianto - 2013-04-29

          guys. can i change integer to string? like this.

          String X_ItCode = A_Tab.getValue("kota");
          String sql= "Select biaya_pokok from a_biaya where kota=?";
          String X_ItDesc = org.compiere.util.DB.getSQLValueString( null, sql, X_ItCode);
          if (X_ItDesc != null)
          {A_Tab.setValue("biaya_pengiriman",X_ItDesc);}
          else
          {A_Tab.setValue("biaya_pengiriman","");}
          }
          result = "";

           
    • Shiju01

      Shiju01 - 2009-08-11

      Thank you all for your time and overwhelming support

      Hi Colin,

      In spite of the code provided (CalloutOrder.java )

      >> mTab.setValue("Description", product.getDescription());  <<

      is not present in version 353A.   That is why  a beanshell callout is attempted.

      So here i wish to confirm after testing 353A is not updating the 

      C_ORDERLINE.Description from M_PRODUCT.Description

      when Product Id is modified.

      Further can you provide a link to know more about  =  "CTX" in code

      >> MProduct product = MProduct.get (ctx, M_Product_ID.intValue());  <<

      Regards
      Shiju

       
    • Shiju01

      Shiju01 - 2009-08-11

      Being a member for ADempiere - House of Commons and taking liberty to Carlos Ruiz  words  i list here the following script - (status: "Chalte-Chalte")

      >>There are lots of things to improve to such callout, for example as Colin advised using model class to get the product, or avoiding to execute the query when the product is not filled, etc.<<

      Window:      : Rule
      Search Key : beanshell:fillProductDesc
      Name          : Fill Product Description
      Event           : Callout
      Rule Type   : JSR 223 Scripting APIs
      Script:
      --------
      package org.compiere.model;

      import java.lang.*;
      import java.util.*;
      import java.util.Properties;
      import java.util.logging.Level;
      import java.sql.*;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Timestamp;
      import java.math.*;  
      import java.math.BigDecimal;
      import java.io.Serializable;  

      import org.adempiere.exceptions.AdempiereException;
      import org.compiere.model.*;
      import org.compiere.util.*;  
      import org.compiere.util.DB;
      import org.compiere.util.DisplayType;
      import org.compiere.util.Env;
      import org.compiere.util.Ini;
      import org.compiere.util.Msg;

      if (A_Tab.getValue("M_Product_ID") != null)

      {

      Integer X_ItCode = (Integer)A_Tab.getValue("M_Product_ID");  
      String sql= "Select Description from M_Product where M_Product_ID=?";
      String X_ItDesc = org.compiere.util.DB.getSQLValueString( null, sql, X_ItCode);

      if (X_ItDesc != null)
      {A_Tab.setValue("Description",X_ItDesc);}
      else
      {A_Tab.setValue("Description","");}

      }

      result = "";

       
    • somya

      somya - 2009-08-23

      Hi everyone
      Good work guys, it surely help community people but i m just thinking of image.
      All image in adempiere get stored in AD_Image table & i want to display the image on orderline tab. I m trying through script callout by taking references of above provided script but i m failing to read it.Is it possible to display image by script callout.

      Thanks.

       
      • salientvijay

        salientvijay - 2009-08-24

        hi !
        Its very easy if you want to display image ont he order line  you can create one foreign key as AD_IMAGE_id and make the referencekey as image . now youcan abletodisplay the image in product line.

        Otherwise if you want to display images related toproduct. Please create one tab in product table with mandatory fields ,Name, AD_image_id(foreign key of AD_image table), product_id(make as parentlink coloum  alsoitshouldbe a foreign key of product  table).

        Using this tab you can upload image for each product.

        Now  you have to write callout in orderline product field ,if product is selected it has to fetch the related image id for product  and set that image_id aastoyour orderline image_id . It will work fine exactlly.

        if you face any problem pleasecaontact me at salientvijay@gmail.com

        Thanks & regards
        vijay

         
  • Akos Gabriel

    Akos Gabriel - 2009-10-30

    Hi,

    I'd like to experiment (heavily) with beanshell script callout :)
    Is there a (complete) documentation of what API calls can I do there?
    Or is there a logical way how one could collect that?
    I see here some magic code which apparently works but I can't extend it without understanding it (and the environment).

    Thanks for the help,

    Akos

     
  • Akos Gabriel

    Akos Gabriel - 2009-11-03

    Hi Shiju,

    Thanks for the info. Before asking, I saw these links.
    I have some experience with BSH programming, I know performance won't be a problem here.

    I would like to have some information about the available objects for the BSH script at runtime, since it is not documented in Adempiere wiki.
    If I won't get an answer to my question: no problem. I will reverse engineer it , and create a documentation about it in my own wiki.

    I don't think that my english would be so bad or my question would be so hard to understand, I just recognise this as an &quot;insider info&quot; that has &quot;business value&quot; so it is not published.

    It's all understood now, thread closed.

    Regards,
    Akos

     
  • Shiju01

    Shiju01 - 2009-11-03

    Hi Akos

    I don't know exactly wether there is an &quot;INSIDER INFO&quot; as you claim.

    To me its just like wether there is &quot;Water in the MOON?&quot;

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-11-03

    Gabriel, about:

    &gt; &quot;I don't think that my english would be
    &gt; so bad or my question would be so hard
    &gt; to understand, I just recognise this
    &gt; as an &quot;insider info&quot; that has
    &gt; &quot;business value&quot; so it is not
    &gt; published.&quot;

    I see you blaming here and there for not getting the answers you want (and maybe this is related to your ask for me in twitter to answer here).

    I don't think the problem is your english, or question hard to understand.  Instead of I think your question is too general, it doesn't show you're doing your homework - this is researching and asking here specific problems you have.

    I always hate the &quot;please give me step by step instructions&quot; kind of questions.

    Your claim about &quot;lack of documentation&quot; is ignoring the fact that there are plenty of documentation and even working examples on your case.

    And your claim that some &quot;insider info&quot; is not published trying to get business is just self-defeating, now I don't like to answer your questions  :-(

    Regards,

    Carlos Ruiz

     
  • Akos Gabriel

    Akos Gabriel - 2009-11-03

    Ruiz and others,

    (attention, long theoretical post follows)

    The post is not directed to anyone, just should be considered maybe.

    No, I'm not blaming for &quot;not getting the answer&quot;. I would not blame at all if I don't get any answer. I understand, people have limited time and/or knowledge, and noone had the time+knowledge right now to answer my question.

    But in this case I felt that I got a &quot;pseudo answer&quot;, pointing me to the documentation I've already read (and I wrote that I'm through all the docs). These pseudo answers tell me that I should pay a bit and then I'd get the information. And this is irritating me, although I understand the motivation fully.

    At this time I don't want to pay for this since I have the time and knowledge to find out myself sooner or later, without any external help. But then the question arises: if nobody invested the time to document what I ask for, why should I do that? More precisely: I'm kinda sure that documentation exists, it is just not published.

    Documenting things to a certain level generates business, this is a good marketing strategy. Let&quot;s call this level: medium.
    Documenting things above this level (above medium) means less consulting need, thus less consulting hours sold. This is weakening the marketing strategy described before.

    I can fully understand this strategy as well, just it has to be made clear. A lot of open-source projects (for example JasperReports) are doing this, I have no problem with this at all. It just has to be told clearly. Then I don't waste time asking and reading the useless (marketing) answers.

    Regards,
    Akos Gabriel

     
  • Akos Gabriel

    Akos Gabriel - 2009-11-03

    Carlos,

    Answers I expected for my question:

    Look at x and y clases in the source, their methods can be used within script callout. x class with context A, y class with context B.
    And so on.

    I've tried your example code and it works even for me.
    I won't complain any more about documentation since I would be able to find my answer in the time I wrote my previous post.

    Regards,
    AKOS Gabriel

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-11-03

    Gabriel,

    &gt; &quot;These pseudo answers tell me that I
    &gt; should pay a bit and then I'd get the
    &gt; information&quot;

    I re-read (several times) the answers you got, and I didn't find anybody compelling you to pay anybody.

    It's obvious knowledge costs - you can pay somebody to teach you, you can learn by yourself (in this case the cost is your time and effort), you can ask in forums hoping somebody know the answer and give it to you, or hoping some charitable soul do your homework.

    There are plenty of options, and each option has an implied cost.

    &gt; &quot;But then the question arises: if
    &gt; nobody invested the time to document
    &gt; what I ask for, why should I do that?&quot;

    Indeed is a really tricky selfish question, why should I wrote the scripting option for Adempiere and release it for you to use it?

    Why did I took the time to write documentation for this development?

    Why did I took the time to write even a working example to help you to understand?

    Now, why must I help you to learn beanshell?  What must be my motivation to let you learn something that you're going to exploit mostly for yourself, and probably not returning anything to Adempiere project?

    Any time somebody ask me for SPECIFIC help about the scripting option I give help.  But you're asking us to help you to learn a script language.  And asking us for MORE documentation because you think somebody else must document it for you.  And then you complain that you're not motivated to contribute documentation, even when you're using programs that others wrote.

    Sorry, I don't like what I'm reading here.

    &gt; &quot;Documenting things to a certain level
    &gt; generates business … Documenting
    &gt; things above this level … means less
    &gt; consulting need … I can fully
    &gt; understand this strategy as well, just
    &gt; it has to be made clear&quot;

    Gabriel, although I'm sure there are certain contributions described like you wrote, you must not generalize.

    With these statements you're generalizing, and I think this is a very wide community.  There are people that contribute a little and hide a lot, there are people that contribute a lot and hide a little, and there are people that contribute without hiding anything.  (Well, and there are also people that hide everything)

    It's not fair putting all developers, implementors and community on the same bag.

    At least from my side, practically all my developments are documented in wiki, trackers, explained cases of use, samples, seed sample data, etc.  So, I don't find fair your statements about this.  I consider the documentation I provided for script callouts is enough, in this specific case going deep it's easier reading code than reading some documentation (that becomes obsolete easily).

    Also you can take training on beanshell, but probably not here.

    Anyways, I need to express also my opinion as I feel unfair these kind of statements.

    Regards,

    Carlos Ruiz

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.