Looping using CreateRecord API

Posted by Rollbase User on 10-Jun-2013 19:16

I have 3 Objects: 1. Member 2. Training 3. Individual Records "Member" 001 Juan Dela Cruz "Training" (Group by Type of Training Program) Core Programs 001 Members Orientation 002 Achieving Service Excellence 003 Train the Trainer Public Seminar 004 Rollbase Training "Individual Records" ID# Member Name Training Program Status 001 Juan Dela Cruz Members Orientation Not yet Attended 002 Juan Dela Cruz Achieving Service Excellence Not yet Attended 003 Juan Dela Cruz Train the Trainer Not yet Attended What I want to do is to create an auto creation of records to "Individual Records" Object everytime there's a New Members created from Members Object. For example, if we created a New Member named Pedro Perez, it should auto create records to Individual Records Object with all the "Core Programs" except for "Public Seminars" Trainings and with a default status of Not yet Attended. I have these scripts below: var query =

All Replies

Posted by Admin on 12-Jun-2013 02:51

Gener,



What you are trying to do makes sense and the explanation is clear but a couple followup questions:

1. Where are you using this script? I assume in a Trigger. If so what kind of trigger is it and when does it run?

2. Is the above the full code of your trigger?

3. Is the query returning any records? i.e. what is the size your "query" array when this code is executed.



You may already know this but the rbv_api.printArr() method prints to the trigger debugger so you will not get any output from that at runtime other than to the trigger debugger window.



Also it is OK if this code returns null since there is no return statement. What you have written is object script which executes arbitrary JavaScript. In this case your goal is to create new records rather than returning a specific result. So returning null is not a problem here.



Matt

Posted by Admin on 12-Jun-2013 03:37

Hi Matt,

Thank you for the response. I will answer your questions below.



1. I'm using the script in Object Script Trigger. It runs After Create.

2. The code above is the full code but essentially it's not final since I'm having a problem on figuring out what i wanted to do.

3. The query does not returns since I haven't put a return function. But since I'd debugged it using rbv_api.printArr(), it returns all "Trainings" IDs as i wanted to.



My objective is to pass the query result (all trainings from Training Object) to the looping Arrays. I can't figure out how to do this in coding and also imparting the CreateRecord Api syntax. I'd also come up this code below:



var arr = rbv_api.selectQuery("SELECT id FROM training3 WHERE type_of_program IN ( 'Core Programs','3 Level Leader Programs')", 1000);

rbv_api.printArr(arr); //for debugging purpose or printing the array



var ids = new Array();

for (var i=0; i

ids[i] = arr[i][0];

ids["R125763023"] = {!id}; // id# of Member (from Mem

This thread is closed