How to fetch a field value in another doctype

I have a doctype name seed license no. i want to fetch that no in sales invoice. the seed license no have a list in which i have given no according to the state . please help. as i am new to erpnext

1 Like

Create a custom field in sales invoice. Choose “Link” type. In Options, write “Seed License no” ( exact name of the doctype you created). This way you stablish a link between both doctypes.

If you need another field from Seed License, you can add new custom field on Sales Invoice and “call it” using “Fetch from”.

There is a lot of docs related to this. Search “link” or “fetch”. You will feel the breeze :wink:

Hope this helps.

1 Like

i tried it…it is not working

Please, share screenshots of your doctypes, and the options of each field involved. Probably, there is something wrong on doctype name, or field name …

this is my seed license no list

i want that no in this field

@SonaID . See this:

Seed License No Doctype definition …

Sales Invoice Doctype customization …

Custom field details …

Should work this way …

Hope this helps.

Thanks AVC… I dont want to select it manually…can you help me with the custom script?

Yes, i will try … So, the id (MH-01, MH-02 …) must be fetched from Seed License No. using Shipping Address State?

Anyway, I think that you should use different approach. Create State as a Doctype, and Seed License No as a field into it, fetching as I wrote before … No custom script would be needed this way.

Thanks AVC. :slightly_smiling_face:

if you got the solution let me know… as client requirement is not manually. they want it auto populate


Create a client script for Doctype Sales Invoice. (and enable it :slight_smile: )

frappe.ui.form.on('Sales Invoice', {
	your_shipping_address_state: function(frm) {{
            method: 'frappe.client.get_value',
            args: {
                'doctype': 'Seed License No',
                'filters': {'your_state_field': frm.doc.your_shipping_address_state},
                'fieldname': ['name']
            callback: function(r) {
                if (r.message) {
                    frm.set_value('your_seed_license_code', r.message.state);


Where …

your_state_field → The field in “Seed License No” that contains the state.
your_seed_license_code → The field in “Sales Invoice” that contains Seed License No
your_shipping_address_state → The field in “Sales Invoice” that contains the destination shipping state.
name → The name of the Seed License No

This script updates the field “your_seed_license_code” when “your_shipping_address_state” value changes.

Review the fields and doctype names, probably you need change something … i don’t know real names you used.

Hope this helps.


Thank you so much!!!

this is my code …it showing me some error

this is the error

this is my seed license no doctype

Please, check the fields “realname”. Put your mouse pointer overthe field and you will see this.

I think that this name maybe is wrong …

'filters': {'**your_state_field**' ...

it is same

I mean the state field name on the other doctype.