How to avoid duplicated records - Forum - Rollbase - Progress Community

How to avoid duplicated records

 Forum

How to avoid duplicated records

This question is not answered

Scenario: 

Object A has a trigger: when the status field changed to "1", create a record in Object B.

When the status field of A changed back to "0", there is no trigger, we want keep the record in B.

However, when we change the status of A to "1" again, the trigger will create another record in B, which is duplicated.

Is there an option to check whether the record is exist in B before the trigger is triggered?? Thanks.

All Replies
  • Hi Cayla,

    I understand that you might be using "Create New Record" trigger on the related objects.In that respect is no out of the box way to perform this in your use case.

     You can try below options:

     1. Include Trigger script to validate the existing records before creating.

     Or

     2. Include a field level validation NOT to allow duplicates.

     

    Please correct me if my understanding is not correct.

    Regards,

    Mani.

  • Hi Caylali,

    As Mani mentioned in the earlier post, you can restrict , creation of duplicate records by checking the value "Do not allow duplicate values" in the field of object definition.

    I have created two workflow status "0" and "1" , created " status change workflow action" by selecting a trigger of type "object script".

    Attaching app.xml for your reference. Please let me know if you need any assistance.SampleApp_v2.xml

  • Thanks Mani and Shiva. I tried to check he value"Do not allow duplicated values" for Object B, and then change the status of Object A, it returns an error, and wont allow me to change the status.

    "Error executing Trigger: "CreateRecordInB" Error ObjectB "somevalue" is already in use. "

    I will try to write the script to search in Object B and then decide whether to create record in Object B or update the current record or do nothing. If there is existing code sample for this function, please let me know. Thanks.

  • Hi caylali,

    Here is sample code, I tried to get record count for field 'myfield' having value 'myvalue', Edit below query with respective tokens for your object.

    var count=rbv_api.selectQuery("SELECT count(*) FROM secondobj where myfield='myvalue'", 1);

    if(count[0][0]>0)

    {

    //skip , record already exists

    }

    else

    {

    //create record

    }

    Thanks,

    Siddeshwar.

  • Hi Siddeshwar,

    Thanks for your response. I have set up a trigger to create a merchant record when the merchant name is not exist yet. I used your code ,but it always returns false no matter whether "x" is in "Merchant" or not.

    var count=rbv_api.selectQuery("SELECT count(*) FROM Merchant where name='x'", 1);

    if(count[0][0]>0){

     return false;

    }

    else

     return true;

  • Hi caylali,

    The above code is working fine for me.

    Can you check the integration name for Object is 'Merchant' and field integration name is 'name' for the field that you want check condition.

    Thanks,

    Siddeshwar.