Trigger - Unique Field Combination Not Working as expected

Posted by IramK on 27-Apr-2015 11:18

Hello,

I am trying to use an unique field combination trigger that is not working as it was back in version 3.0.5.0. Below is the code for the unique field combination formula:

if("{!R58328.id}" !== "0")
{
  // First return the related Opp. Contact records for that ID
  var returnedIDs = rbv_api.getRelatedIds("R58328", {!R58328.id});

  var result = false;

  // Then get the Contact ID's for all those Opp Contacts
  for(var i = 0; i < returnedIDs.length; i++)
  {
    var value = rbv_api.getRelatedFields("R58300", returnedIDs[ i ], "id");
    var returnedContactID = value[0];
    
// Compare this value with the actual field value and see if there is something already present in the list of Opp contact records if("{!contactId}" != returnedContactID) { result = false; } else { result = true; break; } } return result; }

So basically the above code first gets related IDs for a parent Object Record : lets say: 12345, 23456, 34567 (related records) and then I search for the "id" value for a related object called using the getRelatedFields function after which I'm comparing that id with other records contact "id" to make sure there aren't any more available. If there is: then I return true and throw an error.

All Replies

Posted by Orchid Corpin on 27-Apr-2015 18:33

Hi IramK,

Can I have a test XML or maybe generic objects representing the relationships to R58328 and R58300, this would help me build the test app to test the functionality.

Also, since this is a Unique Field combination trigger, what are the fields in "Selected Fields" area?

Thank you.

Regards,

Orchid

Posted by IramK on 28-Apr-2015 04:58

Hello [mention:e6fb884e9c7b45a2a638966c06dc0941:e9ed411860ed4f2ba0265705b8793d05] ,

I just recreated the same trigger without the above mentioned code in the new version i.e. 3.2.0.0 and it started working without any issues. Its as though the migrated triggers from the old version 3.0.5.0 don't seem to work as they did in the older version. Recreating the same trigger in the new release seems to get rid of the issue.

Posted by Orchid Corpin on 28-Apr-2015 13:25

Good to know, so this seems to be working fine in the latest version.

Posted by IramK on 29-Apr-2015 03:12

Yes creating a similar trigger with the same properties and deleting the migrated trigger does work in the latest version but I'm worried that the migration of apps from version 3.0.5.0 to 3.2.0.0 did not get the triggers across properly. My other triggers were failing as well and I'm guessing its too do with the same thing i.e. Migration. Could you possibly check this whether migrating an app with a trigger like the one I mentioned above works in the latest release as well as expected?

Posted by Orchid Corpin on 29-Apr-2015 11:44

Have you tried in 3.0.5 to remove the code above? I saw at the above comment that in 3.2.0.0 you remove the mentioned code and starts working fine. I'm thinking if the conditions in the codes returned false then checking of unique field values will be ignored.

Regards,

Orchid

Posted by cohezive on 30-Apr-2015 10:39

I don't know if this is related to the issue, but the following items jumped out at me:

if("{!R58328.id}" !== "0")  <------------------ I would suggest testing for > 0 (I have seen a -1 value for this test)

{

 // First return the related Opp. Contact records for that ID

 var returnedIDs = rbv_api.getRelatedIds("R58328", {!R58328.id});  <---- This logic could end up selecting the wrong Id

In Parent/Child relationships, the parent reference for Object scripts is defined as {!Pobjectintegrationname#id}.  Otherwise, how do you know which Object is being selected in the relationship if its a multi-level hierarchy?

Posted by Orchid Corpin on 05-May-2015 17:31

Thanks cohenzive for sharing, in conditions I do usually use if({!R123456#id} > 0) ---> it is ok to use this even multiple-value lookups

-Orkid

This thread is closed