[SOLVED] Custom field link

I’ve created a custom field (‘catno’) in “Item”, the value of which I would like to automatically populate a similar field in “Purchase Order Item”. Ultimately, I want the catno value to appear in the printed Purchase Order Form.

In both forms the fields are named ‘catno’.
As Administrator, I’ve tried adding the following custom script to ‘Purchase Order Item’, without success:
cur_frm.add_fetch(‘item’,‘catno’,‘catno’);

What am I doing wrong ?!

Thanks
David

ERPNext: v5.0.0-beta
Frappe Framework: v5.0.0-beta

Can you try and clear cache?

It can be done via help menu in toolbar

Help > Clear Cache

In V5 I don’t see “Help” or “Clear Cache”.
I can only see “Reload” – which I do obsessively!

1 Like

Try this script.
Also check you are writing this in Purchase Order, Not in Purchase Order Item.

cur_frm.add_fetch('item_name','catno','catno');
1 Like

Thank you, Kolate.

Using the following in Purchase Order:
cur_frm.add_fetch(‘item_code’,‘catno’,‘catno’);
got me a bit closer: The value of the custom field (‘catno’) is now correctly populated in the line item of the Purchase Order.

Unfortunately when I then go to save the purchase order, I get the following error:
Could not find Row #1: CatNo: X0145T
Did Not Save

*X0145T is the correctly populated custom field value

Any suggestions?

Link validation error ?

"Traceback (innermost last):
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 18, in savedocs
    doc.save()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 214, in save
    self.insert()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 177, in insert
    self._validate()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 299, in _validate
    self._validate_links()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 471, in _validate_links
    frappe.LinkValidationError)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 248, in throw
    msgprint(msg, raise_exception=exc)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 241, in msgprint
    _raise_exception()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 226, in _raise_exception
    raise raise_exception, encode(msg)
 LinkValidationError: Could not find Row #1: CatNo: X0145T
" desk.min.js:195:94

"Traceback (innermost last):
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/app.py", line 51, in application
    response = frappe.handler.handle()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/handler.py", line 62, in handle
    execute_cmd(cmd)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/handler.py", line 85, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 734, in call
    return fn(*args, **newargs)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 18, in savedocs
    doc.save()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 214, in save
    self.insert()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 177, in insert
    self._validate()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 299, in _validate
    self._validate_links()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 471, in _validate_links
    frappe.LinkValidationError)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 248, in throw
    msgprint(msg, raise_exception=exc)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 241, in msgprint
    _raise_exception()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 226, in _raise_exception
    raise raise_exception, encode(msg)
 LinkValidationError: Could not find Row #1: CatNo: X0145T
" desk.min.js:195:94

Can someone kindly explain how I can solve this error?
Thank you

@rmehta Would you be able to give me some guidance on this?

What causes this Link Validation Error?
I checked the data via MySQL and the values are present and appear ok to me.
I just ran bench update – which appeared to run without error.

Thank you !
David

SOLVED

I managed to correct this error by ensuring that the ‘catno’ field in both forms was of the same type: ‘Data’.
Previously, one was of data type ‘Data’ ( in form ‘Item’ ) and the other was data type ‘Link’’ ( in form ‘Purchase Order Item’).

It remains unclear to me if this is a bug or simply my naive misunderstanding of the data structure.

1 Like