Fetch DocType name and value

In Payment Entry, i have to fetch an doctype in two fields.
In section “Type of Payment”, i have two fields who fetch an doctype, party_type and type
Party_type return the name of doctype
Type return the value of doctype

My customer requires that i add Employee DocType to this fields too.
Someone can help me how can i do this with example please? It’s an custom script?!

first, add Custom Fields on Payment Entry
refer Custom Field

for fetching a value from Link Doctype use add_fetch.

Custom Script Fetch Values From Master

1 Like

I can’t add doctypes on this fields? I have to create an custom field?

Leonardo, I think you may be confusing the terminology.
DocType = a document schema with HTML/JS rendering information in Frappe/ERPNext, stored as a JSON object
Custom Field = a field within a DocType that has been added by the user/administrator
For example, ‘Barcode’ is field in the ‘Item’ DocType. ‘Leonardo’s Special Product Nickname’ would be a Custom Field in the Item DocType.

Hummm i see… So, how can i fetch the Employee variable inside of this fields?

Let me restate to make sure I understand your problem:

You want to add an employee field to the DocType ‘Payment Entry’? This is so that you can track the employee receiving the ‘Payment Entry’?
Can you explain the business case for ‘party type’ custom DocType? It’s not clear to me how they are related.
Don’t be afraid of verbose and use-case-specific explanations on this forum, generally it will get you better support from the community.

Generally fetches are organized as: add_fetch(link_fieldname, source_fieldname, target_fieldname)
So your employee fetch might look like add_fetch(‘employee’, ‘employee_name’, ‘employee_name’)
Here’s the Employee DocType schema: link

Good luck!

3 Likes

I’m doing an example for you, one momment

1 Like

This is what the field does(is translated to pt-br):

If i select Supplier, return my list of Suppliers in the next field:

My list of suppliers:

I wanna add Employee to do the same thing:

My Employees list:

Gotcha. There’s more than one way to do this, but here are a couple suggestions:
The least amount of code and one that leverages the most amount of Frappe core code is to have your select hide/unhide your custom fields that link to supplier and employee.
You can find more about the hide technique by searching the forum.
You can also hide using jQuery if you feel more comfortable with that.
There’s also a "collapse depends on’ field that you can try out at the section break level.

Conheça também @max_morais_dmm, desenvolvedora no Brasil. Ele pode estar disponível para suporte pago na língua portuguesa. Ele é um membro valioso de nossa comunidade de ERPNext.

The technique to hide i have some knowlege, but i wanna fetch employee in this field, in this section like the picture.
How can i fetch this? Custom script?

@Leonardo_Augusto

Link field fetches the list of Linked Doctype.
As your requirements to show Employee as well as Supplier.

Use Dynamic Link Field

1 Like

You can create a custom field, define it as a link to employee and the employees will auto-suggest.
If I understand your design correctly, you’ll have to add BOTH employee and supplier custom fields and have one of them always hidden.
Also, it’s a bad design to have a required field hidden. It would be better if you don’t ask me how I know…

@Leonardo_Augusto
@Sangram and I are saying the same thing differently. You’re on the right track.

No, the supplier its just example to understand what the field does and this is what i wanna do with employee too.
The supplier is ready as you can see.
I will try this now and i show the result for you guys, thanks for help!

But why i have to create a custom field? I can’t fetch employee inside of party type?
I want to do this as an example in the images

Yes, you can’t fetch both Employee and Supplier in Link Field.
The alternative for this is Dynamic Link which gives you Employee or Supplier.
Depends on Doctype (Supplier/Employee) provided in custom_field

Please go through Dynamic Link for more details

But how this field fetch two values then?

You need two fields if you want to store two values. @Sangram indicated this already:

Yes, you can’t fetch both Employee and Supplier in Link Field.

@Sangram’s Dynamic Link solution will let you choose one or the other but not both. Using the regular link field type, it will fetch and auto suggest for each of the linked doctypes (supplier and customer).

I don’t wanna store two values.
I just wanna fetch Employee and the next list will show all of my employees.
The photos is just to show what i wanna do.
But idk how can i fetch this, just it…

I think I understand now. You will not need a custom script. You will have to add a custom field and perhaps hide the supplier field if you do not want it to show up. You do not need a custom script, all the functionality is built in, you just need to use it right.

https://frappe.github.io/frappe/user/en/tutorial/naming-and-linking - scroll to the section on Link and Select Fields
https://frappe.github.io/frappe/user/pt/tutorial/naming-and-linking- Em Portuguese: Vinculando e selecionando campos

It seems like you would benefit from working through the whole tutorial, which is fundamental to understanding Frappe framework structure and features. I cannot stress this enough, it’s absolutely worth the time because it will save you a lot of pain in the future.

1 Like