Anyone out there to post a sample Client Script to fetch the field value of the last record from custom doctype and automatically fill to the new field during new creation? only to get the idea
This is all just typed from memory, and there are almost certainly bugs. You might run into a problem where the new document actually fetches itself rather than the previous document created, in which case you’ll need some logic to check for that.
In any case, doing this with a client script is probably not the right approach anyway, as server scripts (python) are more reliable for important business logic. This should, however, get you started. Please make sure you’ve gone through the link I posted in my last post for more details.
Hi:
As you’ve said before, “I am trying to get and put last four field value to my new created record”
A trigger defines which event starts the function. When you exactly want to fetch and assign data? Maybe when you save the new record. Right? The trigger should be “before_save” (without quotation marks).
Create a client script linked to target doctype.
Anyway … are you working with child doctypes?
@avc@peterg Thank you so much, really really appreciate your time
When you exactly want to fetch and assign data?
Before saving
Maybe when you save the new record. Right?
Yes
are you working with child doctypes?
I only have Monitoring doctype
FYI: programmatically, why i need to fetch the last four fields in my Monitoring doctype record? to calculate the difference between yesterday and today to put the value other field.
There are really much better ways to do this. Duplicating yesterday’s data in today’s document isn’t generally a good practice. For what you’re trying to do, you’re probably better off using a report of some type.
Yes, indeed. All client scripts do is automate data entry. They’re not really meant to do analysis. Comparing and aggregating values in different documents is precisely what reports are designed to do.
Is there any link or documentations to do the report something like what need to be done, I don’t have any idea scripting in report, I can write client script for calculation if the required fields value is there. that’s why I would refer to do it in the form side.
Agree with @peterg . Duplicate data in each new record may result unconsistent … The report just should show data of each record and add values of previous record. Probably that’s the best way.
Anyway, “refresh” event occurs every time you load a form. Note that this behavior will overwrite your previous data. Try “setup” event instead, this only occurs just on record creation.
Sorry James, I can’t help you any further. There’s a syntax error in the code I posted, as I said there probably would be. It’s missing a ) somewhere. If you’re not able to track down the problem and fix it yourself, I’d encourage you to back up a step and spend some time learning javascript. This forum is not really well suited to the kind of support you are needing.