auto filled data from previous record

beycos
Tera Contributor

Hi everyone,

 

In my scenario, a new record is automatically created in the system every six months for each user. I want the newly created record to be pre-populated with the data that the same user submitted in their previous record.

 

What would be the best way to implement this functionality?

Thank you 

Beyza

10 REPLIES 10

Anand Kumar P
Giga Patron

Hi @beycos ,

Create a Scheduled Job:

  • In navigation menu, type "Scheduled Jobs" in the search bar and select "Scheduled Jobs." Click on "New" to create a new Scheduled Job record.

    Configure the Scheduled Job:
    • Provide a name and description for the Scheduled Job.
    • In the "Run" field, select "Recurring."
    • Choose the appropriate interval. In your case, you want the job to run twice a year, so select "Months" and set the interval to "6."

       

    • Select the Script or Business Logic:

      • In the "Script" section, provide the script or business logic that you want the Scheduled Job to execute on the specified dates.
      • var grIn= new GlideRecord('Custom table');
        grIn.initialize();
        grIn.fieldname1="Data";
        grIn.fieldname2secondtable="Data2";
        grIn.insert();​


        Mark it as helpful and solution proposed if it serves your purpose.
        Thanks,
        Anand

Thank you Anand for your quick response.

 When a new record is created in the X table, new records are automatically generated in the Y table. I want these new records in the Y table to be auto-filled with data from the same user's previous record. The system already creates new records, but I need them to be auto-filled with the previous data.

Thank you 

Regards

Beyza

Animesh Das2
Mega Sage
Mega Sage

Hi @beycos ,

 

You can create a before insert BR on the table that should solve the purpose.

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

 

 

Hello Animesh , 

Thank you your quick response as well. I would really appreciate it could you please check the script??  

asign to field is reference field. 
(function executeRule(current, previous /*null when async*/ ) {
 var targetUserSysId = 'aa55a5a5a5a5a5a5a5a5a5a5a';  // users sys_id
 if (current.u_assign_to == targetUserSysId) {

        {
            var gr = new GlideRecord('u_y'); // Target table
            gr.addQuery('u_assign_to', targetUserSysId); // Match the same user reference
            gr.orderByDesc('sys_created_on'); // Sort by creation date (most recent first)
            gr.setLimit(1); // Fetch only the latest record
            gr.query();
            if (gr.next()) {
                // Copy the field value from the found record to the current record

                current.u_1_hr = gr.u_1_hr;
                current.u_10_min = gr.u_10_min;
                current.update();
            }
        }
    }
})(current, previous);
 
 At the moment this is not working. Can you see anything wrong in this script?? 
thank you and Best regards
Beyza