How to Troubleshoot a Server Script?

Hello,

I’m trying to write a server script, which is not working. Is there any built-in way or external tools to troubleshoot and find out why it is not working?

Thanks,
Paul

Hi there,

It depends on what isn’t working. Can you be more specific?

The idea is to transfer custom field info (custom_m_lot_number and custom_m_expiry_date) from the Purchase Receipt Item child table (link field is items) to the generated Batch numbers, via the Serial and Batch Bundle ID which is generated and also in the Purchase Receipt Item line.

This is trying to rework a previously working v14 script, which no longer works due to the change to using Serial and Batch Bundle. Previously the Batch number appeared in the Purchase Receipt Item after submission but it no longer functional and the way to find it programmatically is via the link to the Serial and Batch Bundle entry, which has a child table (link field entries) with the Batch number present.

for item in doc.items:
    if item.custom_m_lot_number and item.serial_and_batch_bundle:
        batch_doc = frappe.db.get_value('serial_and_batch_bundle', entries.batch_no)
        if batch_doc.reference_doctype == doc.doctype and batch_doc.reference_name == doc.name:
            batch_doc.custom_supplier_identifier = item.custom_m_lot_number
            batch_doc.custom_supplier_expiry = item.custom_m_expiry_date
            batch_doc.save()

Tested it and it doesn’t work but trying to figure out where it is not working and not sure where to start

frappe.msgprint(data) is always a good place to start (or just print(data) if you’re on a development server, output to stdout).

Anyway…

I don’t totally follow what you’re trying to do, but this line doesn’t look right. get_value takes three parameters, and I’m not seeing where entries is being defined.

Tip: if you print anything it will show up in response. (Assuming it is document event or API script)

Normal python print works (v15+)

1 Like

Thanks @peterg and @ankush

I tried print(variable) but only seem to get the message that print is undefined, what am I missing?

Ah my bad, this has still not made it to v15 :neutral_face:

you can try log() instead of print.

1 Like