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
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.
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?
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.