0

I have a problem getting the invoice number and invoice line number into a variable.

<script>
const emma = '<%=http2.ResponseText%>';
const obj = JSON.parse(emma);
console.log("object: %O", obj);
console.log(parameters["parameters"][1]["iInvoiceNum"]);
</script>

This is how the console displays. I just want to be able to pass the iInvoiceNum and iInvoiceLine into separate variables.

enter image description here

4
  • Does this answer your question? How do you use Classic ASP string in client side Javascript? Commented Oct 13, 2021 at 9:31
  • You have the object structure in the screenshot follow that and you can't go wrong. Did you even try obj.parameters.ds.iInvoiceNum? Commented Oct 13, 2021 at 9:32
  • You could just have used the dev tools console to test what works e.g. obj.parameters and see what was returned, like already said you have the structure of the object already there for you to play with, dev tools are great for that sort of thing. Commented Oct 13, 2021 at 9:53
  • Does this answer your question? Can't access properties of object after JSON.parse() Commented Oct 13, 2021 at 10:00

2 Answers 2

2

It's not pretty, but should work:

const emma = '<%=http2.ResponseText%>';
const obj = JSON.parse(emma);
const invoiceLine = obj['parameters']['ds']['iInvoiceLine'];
const invoiceNr = obj['parameters']['ds']['iInvoiceNum'];

Alternative:

const emma = '<%=http2.ResponseText%>';
const obj = JSON.parse(emma);
const invoiceLine = obj.parameters.ds.iInvoiceLine;
const invoiceNr = obj.parameters.ds.iInvoiceNum;
Sign up to request clarification or add additional context in comments.

1 Comment

Why not just obj.parameters.ds.iInvoiceNum?
1
const emma = '<%=http2.ResponseText%>';
code hereconst obj = JSON.parse(emma);    
const { iInvoiceLine, iInvoiceNum } = obj.parameters.ds;

1 Comment

This is closer to what I would use personally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.