Set field value via client script

crowell001
Kilo Explorer

I have a demo app with two tables, Attendees and Marketing Events.   The Attendees form/table has a field (events).   The Marketing Events has a field Registered.

In Configure Dictionary for the Registered field, I have the following script as a 'calc'. What I'm attempting to do is to do a count of all records in Attendees where the 'event' field matches the Marketing Event field called 'Name'.   In the Attendees table/form, Event references the Name field in Marketing Event.

However, I am getting nothing out of this - not even logging information.

var count = new GlideAggregate('Attendees');

var vevent = current.Name;

gs.Debug("Returned the value of vEvent = " + vevent);

count.addAggregate('COUNT');

COUNT.QUERY('Event', vevent);

var registered = 0;

if (count.nex()) {

  registered = count.getAggregate('COUNT');

}

gs.Debug("Returned the number of rows = " + registered);

g_form.setValue('registered', registered);

13 REPLIES 13

Hi Curtis,



If it's a calculated field, you don't need to wrap it into an "onLoad" function.



You still need to update the last line like you mentioned:



current.registered = reg;   <Is this required to actually set the value for 'number_of_attendees_registered'?




should be:





current.number_of_attendees_registered = reg; 




After that it should work.




Regards,


Sergiu


Still isn't working.



var count = new GlideAggregate('x_21333_marketing_attendee');


var vevent = g_form.getControl('name');


//var vevent = current.name;


  alert(g_form.getValue('Returned the value of vEvent = ' + vevent));


count.addQuery('event', vevent);


count.addAggregate('COUNT');


count.query();


var reg = 0;


if (count.next()) {


  reg = count.getAggregate('COUNT');


}


  alert("Returned the number of rows = " + reg);


current.number_of_attendees_registered = reg;



Perhaps this should be written as a Business Rule?


Does the alerts shows a number of rows returned?


No, I'm not getting any feedback


Are all the field names used in the script correct, like dictionary for 'name', 'event' ? Is at least first alert working?


Also, this would work after you load the form on which this field is on.



Regards,


Sergiu