Skip to Content
avatar image
Former Member

JavaScript for Script Editor in Workflow - Sap Business One Studio

Hi everyone,

We're starting now to use Worflow in SAP Business One Studio and there's something blocking us the way to get through.

We've a scenario that we have to create. In this scenario, one of the parts is to verify if a specific sales order has a doctotal that is higher than the business partner limit credit. We've seen almost every video online and every JavaScript examples available for this situation but the script is still not working.

We've used a script in the Script Editor, that links to a Exclusive Gateway. The example that we're using is about verifying the stock available, and regarding the result, the workflow returns a delivery or a purchase order creation.

So, what I am asking, is that if it's possible for you to see the code that we use has example and the code that we done.

Our base code:

var order = CurrentProcess.B1Obj('OR1');                                
var total=0;
var itemCode;
var query;
var recordset;
var param;
var lineCnt = order.getDocumentLines().size();
                                for (i=0; i<lineCnt; i++)
                                  {
             itemCode = order.getDocumentLines().get(i).getItemCode();
             query = "select onHand from OITM where itemcode = '" + itemCode + "'";
             print("The query is: " + query + "\r\n");
             recordset=company.getRecordset();
                                                param = company.getRecordsetParams();
                                                param.setQuery(query);
                                                recordset.doQuery(param);
                                                while (recordset.read()) {
                                                print("Reading from OITM\r\n");
                                                var fields = recordset.getFields().toArray();
                                                                for (j=0;j<fields.length;j++) {
                                                                var fld = fields[j];                                                                
                                                                var onHand = fld.getColumnValue();
                                                                print("OnHand=" + onHand + ", quantity=" + order.getDocumentLines().get(i).getQuantity() + "\r\n");
                                                                if(onHand< order.getDocumentLines().get(i).getQuantity()) 
{
                CurrentProcess.DataObject('do2').putItem('needPurchase', 1); 
                print("set needPurchase=1");
                                                             }
                                             } 
                                                // Exit Loop
                                                 }
                                  }

Our current code (not working):

var order = CurrentProcess.B1Obj('Encomenda');                                
var total=0;
var cardCode;
var query;
var recordset;
var param;
var docTotal;
var lineCnt = order.getDocument().size();
                                for (i=0; i<lineCnt; i++)
                                  {
             cardCode = order.getDocument().get(i).getCardCode();
 docTotal = order.getDocument().get(i).getDocTotal();
             query = "select CreditLine from OCRD where CardCode = '" + cardCode + "'";
             print("The query is: " + query + "\r\n");
             recordset=company.getRecordset();
                                                param = company.getRecordsetParams();
                                                param.setQuery(query);
                                                recordset.doQuery(param);
                                                while (recordset.read()) {
                                                print("Reading from ORDR\r\n");
                                                var fields = recordset.getFields().toArray();
                                                                for (j=0;j<fields.length;j++) {
                                                                var fld = fields[j];              
var CreditLine = fld.getColumnValue();
                                                                print("CreditLine=" + CreditLine + ", docTotal=" + order.getDocument().get(i).getDocTotal() + "\r\n");
                                                                if(CreditLine< order.getDocument().get(i).getDocTotal()) 
{
                CurrentProcess.DataObject('Aux').putItem('VerificaLimiteCrédito', 1); 
                print("set VerificaLimiteCrédito=1");
                                                             }
                                             } 
                                                // Exit Loop
                                                 }

After this, we put the two outputs as "false" and with the conditions:

CurrentProcess.DataObject('Encomenda').getItem('VerificaLimiteCredito')=='0'

and

CurrentProcess.DataObject('Encomenda').getItem('VerificaLimiteCredito')=='1'

If there is someone that could help, let me know please.

Thanks in advance.

Regards,

Catarina

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers