dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: JavaScript for Script Editor in Workflow - Sap Business One Studio

  1. #1
    Join Date
    Sep 2017
    Posts
    3

    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

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,432
    For one, what language is that? It has some common elements that could be JavaScript but for all the methods that look like JQuery type framework.

    Also when posting code, please use forum BBCode tags, examples in my signature and if it is JQuery type stuff, then it belongs in the sub forum called JavaScript Frameworks.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Sep 2017
    Posts
    3
    Hello,

    First thank you for your help.
    This is suppose to be Java Script language but as I said we’re only at the beginning of this area of computation and we are really used to work with JQuery language, that must be why this is such a mess.

    I’m trying to write a Java Script condition for a true or false on a workflow that is being structure on SAP Business One Studio.
    My condition must say that if a field from a document is higher than another filed from that document then true and it goes one way on the workflow. If it’s lower then it goes the other way.

    Can you help me writing my Java Script for this example, please?

    Regards,

    Catarina

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,432
    Ok, makes sense.

    Java is not JavaScript, the language Java has nothing to do with JavaScript.

    Have moved to Java for you.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  5. #5
    Join Date
    Sep 2017
    Posts
    3
    Hi,

    Thank you.

    Regards,

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center