Fetching Grid Row's value , Sum them and assign into for

Posted by john cruze on 01-Apr-2016 06:23

Hello All,

how can i fetch a grid row value , Sum them and assign summation value into formula field .

( A grid may have 1, 2 or more row depend on requirement ) . if Detail required about object please let me know.

thanks.

All Replies

Posted by Shiva Duriseati on 04-Apr-2016 07:06

Hi John,

Please specify a function getSumOfRowValues() in "onSubmit" event handler by following the below navigation.

Object Definition->Pages->New->Properties

Add a script component in the new record page by using design the page and define the function as follows.

<script>

function getSumOfRowValues(){

var sumOfRowValues=rbf_sumGridColumn2(0, "marks");
rbf_setFieldValue("Sum", (sumOfRowValues));

}

</script>

 

The function rbf_sumGridColumn2(0, "marks"); will return the sum of all the values of the field "Marks".

And the function rbf_setFieldValue("Sum", (sumOfRowValues)); will set the value to field of type "integer".

Note: Formula field cannot be saved via script component.

Please let me know if this fits your requirement.

Regards,

Shiva

Posted by john cruze on 06-Apr-2016 04:29

Hi Shiva ,

Thanks. I'll try and get that working.

Posted by john cruze on 06-Apr-2016 05:18

Hello All,

can any one suggest that how can i assign calculated grid row value into field of another object.

let say i have two object  Obj1 and Obj2 .

Obj1 has relationship ( one  Obj1 to many Obj2 ) and field of Obj2 is rating configured in grid now

i calculate sum of all rating using  

<script>

function getSum()

{

var sum=rbf_sumGridColumn2(0, "rating");

}

</script>

and i want value of sum should be assigned into Avg field of Obj1 .

i use rbf_setFieldValue('Avg ' , sum ); but didn't get any result.

thanks.

Posted by Shiva Duriseati on 06-Apr-2016 05:59

Hi John,

Are you trying to assign the value of 'sum' to formula field 'Avg?'

Regards,

Shiva

Posted by john cruze on 06-Apr-2016 06:18

Hi Shiva ,

no , its a simple decimal field (avg) . please suggest how can i do for both decimal field as well as

formula field also .

thanks.

Posted by Shiva Duriseati on 06-Apr-2016 07:51

Hi John,

If your object uses both Average(decimal type) and Formula Field then you can use the server side API to get the value of Average and assign it to formula field.

Example: In formula field section include the following code.

var id="{!id}";

var arr=rbv_api.selectQuery("SELECT Average FROM ObjA where id=?", 1, {!id});

return arr[0][0];

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

Regards,

Shiva

[View:/cfs-file/__key/communityserver-discussions-components-files/25/SampleGridControl_5F00_v2.xml:320:240]

This thread is closed