A lot of extra records when using API createrecord with the

Posted by Rollbase User on 23-Jan-2013 05:32

The system creates a bunch of records when using a trigger with the API CreateRecord to create one more record within the grid-control. I have created a trigger (on create) to add one more record in the grid control for each created record. The array contains only one record, but it is really weird why the system creates a lot of records. You can easily reproduce it by creating a trigger on the child (grid control) object which contains: var x = new Array(); x["R56068393"]={!R56068393}; //this is the relation to the header object x["omschrijving"]="Extra record"; rbv_api.createRecord("line_item", x); any idea?

All Replies

Posted by Admin on 23-Jan-2013 11:30

How this trigger is activated? On update?

Posted by Admin on 23-Jan-2013 14:57

No only on-create

Posted by Admin on 23-Jan-2013 15:05

Please use Triggers debugger

Posted by Admin on 23-Jan-2013 15:30

Hi Pavel,

Also here, nothing specials. The environment doesn't contain any records. Only one header record and one line-item record has been saved. After the save i get 70 grid records back in stead of one, weird...



I have reproduce it on different environments, and the array contains only one record. You can put the trigger in the child object and you can see this behaviour.



Here a dump of the debugger:



Running ON_BEFORE_CREATE on null (ID=63485929)

Finished ON_BEFORE_CREATE on null (ID=63485929)



Running ON_AFTER_CREATE on 63485929 (ID=63485929)

Checking trigger: test2 (ID=63475347)

Running test2 on Memoboeking: 63485929 (ID=63485929)

Running VALIDATION_CREATE on null (ID=63485930)

Finished VALIDATION_CREATE on null (ID=63485930)



Running ON_BEFORE_CREATE on null (ID=63485930)

Finished ON_BEFORE_CREATE on null (ID=63485930)



Running ON_AFTER_CREATE on 63485930 (ID=63485930)

Checking trigger: test2 (ID=63475347)

R

Posted by Admin on 23-Jan-2013 15:57

I think this dump explains what is happening:



1. Record with ID=63485929 has been created

2. That invokes trigger: test2 on record (parent) with ID=63475347

3. That creates another record with ID=63485930

4. That goes to #2, so process continues, potentially endlessly



Fortunately there are limits on total number of triggers in one transaction as well as total execution time. Otherwise you could bring down your server.

Posted by Admin on 23-Jan-2013 16:29

Thanks Pavel for the explanation. I will investigate how to manage this. Do you know how we can create one extra record for each self created grid record? Maybe first a loop on the created records to know the count, and after that creating the extra records?



Its a different approach: Using the API createrecord on the on-create trigger -:), fireing one time...

Posted by Admin on 23-Jan-2013 16:49

Try "Create New Record" trigger instead of "Object Script".

Posted by Admin on 23-Jan-2013 17:53

You can also try API

rbv_api.setSharedValue(name, value)

to set a flag that one record has been created, then examine that flag using API

rbv_api.getSharedValue(name)

and do not create any more records if flag was set.

Posted by Admin on 24-Jan-2013 02:46

Thanks Pavel for the information. I will investigate your advise!

This thread is closed