I am trying to get and put last four field value to my new created record from the latest created in my custom doctype order by moni_date field, create a new custom doctype via client side scripting, but I am struggling to find same scenario of mine.
cur_frm.doc.creation see this in the forum to retrieve a created records
Here is the flow:
Get the value of four fields from latest created doctype. - fields: field1, field2, field3, field4, moni_date
Create New Record and put the lates value to the following fields: fieldnew1, fieldnew2, fieldnew3, fieldnew4, moni_last_date
Doctype Name: Monitoring
Last Rec. ------- New Rec.
field1 —> fieldnew1
field2 —> fieldnew2
field3 —> fieldnew3
field4 —> fieldnew4
moni_date—> moni_last_date
I’m not totally follow you here, but if you want to just fetch the last four created documents of a doctype, you can use the get_list method, sorted by creation:
Yes, if you want to automate this process, you could use a client script. Just pick the event you want to have as a trigger, fetch the latest doc, and set the values that you need.
I don’t totally understand your use case here, but this might be better done with a server script. If the data is not critical, a client script may be fine.
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.