getting a date field to auto populate when a new record in a related list created

patricklatella
Mega Sage

Hi helpful friends!

I previous opened a thread with a question to get a date field to auto populate when any change to a form is made, and it worked.   However it does not autopopulate if the first thing that is done on the form is to create a new record from a related list on the record.   Is this possible?

1 ACCEPTED SOLUTION

Ahh !!


I totally forgot that you are using scoped application


replace the below line


gr.date_reviewed = gs.nowDateTime();



with



gr.date_reviewed = new GlideDateTime();


View solution in original post

20 REPLIES 20

Yes. If you can give us the table and field names then we can help you with the script.


should be same as other business rule that you have with couple of changes




Table name changes to the related list table and on insert



and in case if you are using set values you will have to dot walk to the parent fields


patricklatella
Mega Sage

parent table = "x_cur_oc_feedback_oc_feedback"


parent table field I want to auto populate with date/time = "date_reviewed"


child table = "x_cur_oc_feedback_tasks"



trigger to auto poplulate the parent table field (if blank at the time) = when first record in the child table is inserted/saved/updated



thanks!


Write a after insert business rule on x_cur_oc_feedback_tasks table and use the below script



update parent_reference_field



var gr = new GlideRecord('x_cur_oc_feedback_oc_feedback');


gr.addQuery('sys_id', current.parent_reference_field); // parent_reference_field is the field that is relating parent and child table on child form


gr.query();



while(gr.next()){



gr.date_reviewed = gs.nowDateTime();


gr.update();



}


patricklatella
Mega Sage

pretty sure I did that correctly, double checking, but I got the following alert



find_real_file.png