Custom Field Type (Code) Can Java Script be used in this to read and write to the data base?

Custom Field Type (Code) Can Java script be used in this to read and write to the data base?

It’s the opposite of that. Code is used to display code, not execute.

Basically it's the same as preformatted text in this forum.

If you are looking to use javascript, use the custom script feature in settings.

I have already used the code field with java script in the default value field and it executed in the form correctly.Just didn’t know if it would write to the database.

@jayte it scarres me (are you doing it in the very wrong way!)!

Maybe is a nice approach take a look in the tutorial!

http://frappe.github.io/frappe/user/en/

I’m not a programmer and was trying to get a page break that would work when we save to PDF. I was hoping to have a drag and drop field so I could put a page break in our cover pages for quotes. where we needed them. The script generated the page break but it didn’t pass to the PDF. I was getting desperate after trying everything that was suggested to get the print format right.

Now I’m trying to pull the Sales Partner address into our quotes. I’ve tried the
cur_frm.add_fetch(“partner_name”, “address_line1”, “d_address_line1”);
in the custom script and it does not seem to be working. This is straight from the documentation.
I was trying to think of other ways to do what I needed.

If we didn’t have two months of work invested in ERPNext I think I would go with something else. If I was good at Java and Python I might think differently. Pretty frustrated with it right now.

Thanks for the help.

address-line1 is not a valid field name. If anything, it could be address_line1

also, there is a checkbox in sales order item for page break. Not sure why it’s not there in the Quotation. It may be able to be replicated with a custom script.

If you share your code, I will try it on my end and see if I can’t find a solution. No promises though, I’m learning as I go as well!

Edit: For some reason, address is an HTML field. I’m not sure how to go about pulling that information

the ‘address_line1’ is the field in the ‘Address’ table that I need to pull into my quotation. The ‘Sales Partner’ table is where the sales partner name resides that I select in my quotation. I assume that the
cur_frm.add_fetch(“partner_name”, “address_line1”, “d_address_line1”);
is not following the sales partner address back to the address table to get the info.

I get it, but address-line1 cannot be a field name because field names do not allow ‘-’ characters, only letters, numbers, & underscores. Also, the address in Sales Partner is not a table, it’s an HTML field. When you click ‘new address’ or ‘edit’, it’s not opening a table, but redirecting you to the address form. It doesn’t follow the normal style of ERPNext, and I’m not sure why.

Try making a link field in Quotation called sp_address, for the address doctype. Then add this custom script:

cur_frm.fields_dict['sp_address'].get_query = function (doc) { return { filters: { "sales_partner": doc.partner_name } }; };

This script worked for me, it filters the address list to only show that Sales Partner’s address. you will have to add fields for each line of the address, Then you can fetch from that field with additional functions:

cur_frm.add_fetch("sp_address","address_line1","sp_address_line1");

There is almost certainly an easier way to do this, but I don’t know what it is.

Edit: I called the Sales Partner address fields supplier for some reason. changed that.

Sorry, the dash was a typo.

Have not managed to get this working yet.
Here is the script I put in custom scripts-

cur_frm.fields_dict[‘distributor_address’].get_query = function (doc) {
return {
filters: {
“sales_partner”: doc.partner_name
}
};
};
cur_frm.add_fetch(“distributor_address”,“address_line1”,“d_address_line1”);

Do you see anything wrong with this and in the add_fetch line, what type of field should the destination field be in the database?

Thanks for the help. :slight_smile:

It looks like it should work. Have you checked your browser’s console(F12)? There could be an error message there.

EDIT: The destination field should be the same type as the field being fetched from.

I’m getting this-

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check XMLHttpRequest Standard

I’m not sure what that means, someone with more knowledge will have to help you with that one. Sorry… However I do not believe this has anything to do with your current problem…

What version of ERPNext are you running?

@jaytee, turn the d_address_line1 as ReadOnly and put this on the options distributor_address.address_line1

Did not change anything. I had already checked the read only on the field.
I’m perplexed as to why it is working for cpurbaugh but not on our server.

@jaytee, maybe a typo, or a customization in the form, is blocking the fetch process!

Is hard to say, without know what do you have made inside this form!

This is the only custom script I have in the quotation form and the custom fields we have added for it.

Thanks for the help.