cancel
Showing results for 
Search instead for 
Did you mean: 

SAP B1 WorkFlow

0 Kudos

Hi there,

I am new to B1 workflow and I have written this following script for scripted task.


var order = CurrentProcess.B1Obj('OR1');                                
var total=0;
var itemCode;
var query;
var recordset;
var dbname=company.getDatabaseName();
var param;
var lineCnt = order.getDocumentLines().size();
print("NomanWorkflowWorking")
print("total lines are "+lineCnt)


for (i=0; i<lineCnt; i++)
  {
    try {
          itemCode = order.getDocumentLines().get(i).getItemCode();
          print("Selected item is "+itemCode)
          
           query = "SELECT T0.OnHand FROM "+ dbname +".OITM T0 WHERE T0.ItemCode = '"+ itemCode +"'";

           print("Query is "+query)
          
          recordset=company.getRecordset();
          param = company.getRecordsetParams();
          param.setQuery(query);
          recordset.doQuery(param);
          
          print("needPurchase: " + CurrentProcess.DataObject('do2').getItem('needPurchase'))

          while (recordset.read()) 
          {
            
            var field = recordset.getField("OnHand");
            var onHand = field.getColumnValue();
            if(onHand < order.getDocumentLines().get(i).getQuantity()) 
                {
                  
                  CurrentProcess.DataObject('do2').putItem('needPurchase', 1);
                  print("Stock falls to negative inventory for the item: "+itemCode+". Please make a purchase order.")
                  break;
                  
                }
            
          }
                  
        } catch (error) 
        {
        print("Exception hit: "+ error)
        break;
        }
            

  }

But this is giving me following exception regarding some database authentications.

2019-11-24 00:47:50 [DEBUG] [WorkflowEngine-akka.actor.default-dispatcher-265] [DIDataConverter] : com.sap.sbo.wf.interop.diapi.bo.RecordsetParams.getUserFields(), com.sap.sbo.wf.interop.diapi.bo.RecordsetParams.getUserFields() 2019-11-24 00:47:50 [DEBUG] [WorkflowEngine-akka.actor.default-dispatcher-265] [Recordset] : SOAPFaultException caught. Fault Code: a:InternalServiceFault, Message: Client received SOAP Fault from server: Internal error (8180) occurred Please see the server log to find more detail regarding exact cause of the failure. 2019-11-24 00:47:50 [ERROR] [WorkflowEngine-akka.actor.default-dispatcher-265] [Recordset] : Client received SOAP Fault from server: Internal error (8180) occurred Please see the server log to find more detail regarding exact cause of the failure. 2019-11-24 00:47:50 [ERROR] [WorkflowEngine-akka.actor.default-dispatcher-265] [Recordset] : Recordset do query failed, SELECT T0.OnHand FROM Jland.OITM T0 WHERE T0.ItemCode = 'SS1424' 2019-11-24 00:47:50 [ERROR] [WorkflowEngine-akka.actor.default-dispatcher-265] [WFException] : Recordset do query failed, fail to get result. 2019-11-24 00:47:50 [INFO] [WorkflowEngine-akka.actor.default-dispatcher-265] [PrintFunction] : print: Exception hit: com.sap.sbo.wf.engine.exception.WFException: Recordset do query failed, fail to get result.

Any help is much appreciated.

Regards!

Accepted Solutions (0)

Answers (0)