Copy record data to another record using a business rule/macro

Hello -

We have a need in one of our applications to copy data from one record to another record when the status changes to close if both records share an id field value.

Example: copy the value from a date field, the value from a text field and a picklist value when the status is changed to closed from one record to another record if both records share the same value of a field named id (record_1 id = 123 and record_2 id = 123).

Any help would be greatly appreciated.

Hi Dan Ruffcorn,

This can be achieved by a custom field named id because the internal field record_id is unique for all records.
We can copy the data from one record to another record by invoking a business rule having the condition, status equals to closed that executes the below class.

import com.platform.API.*;
public class CopyRecorddata
{
public void copyRecord(Parameters params) throws Exception
{

    String priority =  (String)params.get("priority");
     String subject = (String)params.get("subject");
     String closedate = (String)params.get("date_closed");
     String customid = (String)params.get("custom_id");
     String sql1="SELECT * from OBJECT NAME where custom_id= "+customid ;
     Result Res=Functions.execSQL(sql1);
     ParametersIterator it=Res.getIterator();
     Parameters param = it.next();     
     String recordid=(String)param.get("id");
     Parameters pm = Functions.getParametersInstance(); 
     pm.add("priority", priority );
     pm.add("subject", subject );
     pm.add("date_closed", closedate );
   
       try
    {
      Result result = Functions.updateRecord("OBJECT NAME",recordid,pm);
           
    }
    catch (Exception e)
      {
    
    }
}

}

Regards,
Mudassir Afreen

Thank you for this.

When I implement it, I receive an error (screenshot attached).

Any help would be greatly appreciated.
error.JPG

Hi Dan Ruffcorn,

You are facing this issue because you are not changing the OBJECT NAME and field names. After creating the above class please replace the OBJECT NAME with your object name and the object should contain the fields subject, custom_id, priority and date_closed. Then it will work.

Regards,
Mudassir Afreen

Hello Mudassir Afreen,

Thank you for replying. I appreciate you working with me on this.

I did replace OBJECT NAME with the name of the object I am referencing, and changed the fields subject, priority, and closed date with the fields I want to use. The object I am using is not a case object and therefore does not have the fields close date, subject or priority.

Maybe I explained what I want incorrectly:

When a new person record is added (person object), a field is created called household id. Any person with the same address shares this household id. When one of these persons needs equipment, a request is created (request is the case object). When the request is closed, the equipment (inventory object) is assigned (the way it is assigned is the household id is added the inventory record, the field is called client household id) to the person. I would like this piece of equipment to be assigned to all persons with the same household id.

All 3 objects contain lookups to each object.

Thank you for taking time to help me with this.

Added the code I am using:

package com.platform.copy.copyRecord;
import com.platform.API.*;
public class CopyRecord
{
public void copyRecord(Parameters params) throws Exception
{

String modelname = (String)params.get(“model_name”);
String serialnumber = (String)params.get(“serial_number”);
String installdate = (String)params.get(“install_date”);
String customid = (String)params.get(“client_household_id”);
String sql1="SELECT * from Inventory_Item where household_record= "+customid ;
Result Res=Functions.execSQL(sql1);
ParametersIterator it=Res.getIterator();
Parameters param = it.next();
String recordid=(String)param.get(“id”);
Parameters pm = Functions.getParametersInstance();
pm.add(“model_name”, modelname );
pm.add(“serial_number”, serialnumber );
pm.add(“install_date”, installdate );

try
{
Result result = Functions.updateRecord(“Inventory_Item”,recordid,pm);

}
catch (Exception e)
{

}
}
}

Hi Dan Ruffcorn,

only one user can be a part of the owner. If you want to assign then
1.Create the replica of the same record equal to the number of persons having same household id and assign each record to each person.
or
2. Create teams with the persons having same household id and assign the record to the respective team.

Regards,
Mudassir Afreen