Skip to main content
Solved

URGENT : Bot Error as output while running javascript


Forum|alt.badge.img+2

Hello everyone,

 

I have a requirement for merging the PDFs together, I have a data table containing the two columns (Invoice and Ref Doc Number) and a list containing some PDFs having Ref Doc Number as prefix and I have to merge the invoice with the PDFs having corresponding Ref Doc Number as prefix.

CATCH : A invoice can have multiple Ref Doc Number and a Ref Doc Number can have multiple PDFs.

I have created the input string for the given code containing the data table and the PDF list 

input_json = '{ "datatable" : [ { "Bill. Doc." : "1025294", "Ref. Doc." : "1022069792"}, { "Bill. Doc." : "54427960", "Ref. Doc." : "5750000117"}],

"pdf_list" : ["1022069792yoo","1022069792_test1","1022069792_test2","1022069792_test3","1022069792_test4","1022069792_test5","5750000117huugv","5750000117testtttt","5750000117_test11","5750000117_test2"]}' 

 

and i want the output in such a way I can merge the invoice and the PDF as mentioned above  

CODE : function generateInvoiceMapping(input_json) {
    let data = JSON.parse(input_json);
    let result = {};
    
    data.datatable.forEach(entry => {
        let invoice = entry["Bill. Doc."];
        let refDoc = entry["Ref. Doc."];
        
        if (!result[invoice]) {
            result[invoice] = {};
        }
        
        let matchingPdfs = data.pdf_list.filter(pdf => pdf.startsWith(refDoc));
        
        if (matchingPdfs.length > 0) {
            result[invoice][refDoc] = matchingPdfs;
        }
    });
    
    return JSON.stringify(result);
}

Output : {"1025294":{"1022069792":["1022069792yoo","1022069792_test1","1022069792_test2","1022069792_test3","1022069792_test4","1022069792_test5"]},"54427960":{"5750000117":["5750000117huugv","5750000117testtttt","5750000117_test11","5750000117_test2"]}}

 

ALWAYS GETTING OUTPUT AS ”Bot Error”, Although code is tunning fine in Visual Studio

Best answer by Marc Mueller

Hi ​@AryanGuru ,

As I am not able to get your JavaScript running as expected below is my approach to solve it.

I know this is not what asked for but I am a 🐍Pyhon guy 😉:

 

Maybe you want to try this:

I have put this as strInputJSON variable:


{"datatable": [{"Bill. Doc.":"1025294","Ref. Doc.":"1022069792"},{"Bill. Doc.":"54427960","Ref. Doc.":"5750000117"}],"pdf_list": ["1022069792yoo", "1022069792_test1", "1022069792_test2","1022069792_test3","1022069792_test4","1022069792_test5","5750000117huugv","5750000117testtttt","5750000117_test11","5750000117_test2"]}

 

In “Python Script: Open” action I put this:

import json

def generate_invoice_mapping(input_json):

    data = json.loads(input_json)
    result = {}

    for entry in data["datatable"]:
        invoice = entry["Bill. Doc."]
        ref_doc = entry["Ref. Doc."]

        if invoice not in result:
            result[invoice] = {}

        matching_pdfs = [pdf for pdf in data["pdf_list"] if pdf.startswith(ref_doc)]

        if matching_pdfs:
            result[invoice][ref_doc] = matching_pdfs

    return json.dumps(result)

 

###################################################################

@AryanGuru What do you think?

Cheers

Marc

 

 

 

 

 

View original
Did this topic help answer your question?

12 replies

Marc Mueller
Pathfinder Advocate | Tier 6
Forum|alt.badge.img+13
  • Pathfinder Advocate | Tier 6
  • 133 replies
  • February 17, 2025

Aaron.Gleason
Automation Anywhere Team
Forum|alt.badge.img+10
  • Automation Anywhere Team
  • 503 replies
  • February 17, 2025

Check out the Bot Agent logs, typically here:

C:\ProgramData\AutomationAnywhere\BotRunner\Logs

See if one of the logs shows the JavaScript problem. Visual Studio might be making a concession that Automation Anywhere isn’t, and the only way of knowing is to look at the logs.

If you find something in the logs that you don’t understand, feel free to respond with that log snippet here.


Forum|alt.badge.img+2
  • Author
  • Cadet | Tier 2
  • 5 replies
  • February 17, 2025

@Aaron.Gleason  Logs folder is empty.

 

@Marc 1985 given code is throwing the error, but when I used a very simple function it worked, although error persists for my code


Marc Mueller
Pathfinder Advocate | Tier 6
Forum|alt.badge.img+13
  • Pathfinder Advocate | Tier 6
  • 133 replies
  • February 17, 2025

@AryanGuru Could you post a screenshot of your code in "Lust View"?

  • Note: The Run JavaScript action requires a list variable for its argument(s). You can use the list variable to pass multiple arguments of different data types such a boolean, date/time, number, and string.

Forum|alt.badge.img+2
  • Author
  • Cadet | Tier 2
  • 5 replies
  • February 18, 2025

@Marc 1985  I have only 1 input argument

 


Marc Mueller
Pathfinder Advocate | Tier 6
Forum|alt.badge.img+13
  • Pathfinder Advocate | Tier 6
  • 133 replies
  • February 18, 2025

Hi ​@AryanGuru ,

Could you show us how the list variable looks like which you are using in L47 please?


Marc Mueller
Pathfinder Advocate | Tier 6
Forum|alt.badge.img+13
  • Pathfinder Advocate | Tier 6
  • 133 replies
  • February 18, 2025

@AryanGuru 

Here is the A360 documentation on JavaScript package… (I linked above the browser package one Sorry)

 

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-javascript-command.html


Marc Mueller
Pathfinder Advocate | Tier 6
Forum|alt.badge.img+13
  • Pathfinder Advocate | Tier 6
  • 133 replies
  • February 18, 2025

@arjun.meda I am not an JavaScript expert…

Do we maybe need a node.js installation to execute the code from ​@AryanGuru ?


Forum|alt.badge.img+2
  • Author
  • Cadet | Tier 2
  • 5 replies
  • February 18, 2025

@Marc 1985 

 


Forum|alt.badge.img+2
  • Author
  • Cadet | Tier 2
  • 5 replies
  • February 18, 2025

@Marc 1985 I thought about the node installation, but then the simple code would not have worked


Marc Mueller
Pathfinder Advocate | Tier 6
Forum|alt.badge.img+13
  • Pathfinder Advocate | Tier 6
  • 133 replies
  • Answer
  • February 19, 2025

Hi ​@AryanGuru ,

As I am not able to get your JavaScript running as expected below is my approach to solve it.

I know this is not what asked for but I am a 🐍Pyhon guy 😉:

 

Maybe you want to try this:

I have put this as strInputJSON variable:


{"datatable": [{"Bill. Doc.":"1025294","Ref. Doc.":"1022069792"},{"Bill. Doc.":"54427960","Ref. Doc.":"5750000117"}],"pdf_list": ["1022069792yoo", "1022069792_test1", "1022069792_test2","1022069792_test3","1022069792_test4","1022069792_test5","5750000117huugv","5750000117testtttt","5750000117_test11","5750000117_test2"]}

 

In “Python Script: Open” action I put this:

import json

def generate_invoice_mapping(input_json):

    data = json.loads(input_json)
    result = {}

    for entry in data["datatable"]:
        invoice = entry["Bill. Doc."]
        ref_doc = entry["Ref. Doc."]

        if invoice not in result:
            result[invoice] = {}

        matching_pdfs = [pdf for pdf in data["pdf_list"] if pdf.startswith(ref_doc)]

        if matching_pdfs:
            result[invoice][ref_doc] = matching_pdfs

    return json.dumps(result)

 

###################################################################

@AryanGuru What do you think?

Cheers

Marc

 

 

 

 

 


Forum|alt.badge.img+2
  • Author
  • Cadet | Tier 2
  • 5 replies
  • February 19, 2025

@Marc 1985, as i can see, the code is same, and it is working it expected, even I tried python at first but I can’t install python in my work laptop without getting non-complaint, that’s why I am using JS.

Although, thanks a lot for the efforts 😊


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings