- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 10:22 PM
Hello Community,
I want to populate a field called total sum on a record producer form with a total sum of the fields inside an MRVS.
I was able to achieve this using an onSubmit catalog client script, but it only populates the data when user submits the form using submit button.
Is there any way that when user clicks on ADD button on MRVS then it populates the field outside MRVS.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 06:04 AM
hello
yes its possible .Follow the below steps to do it
1)Create simple widget like below and use the below code in client controller of the widget
In the if loop replace testing with your MVRS internal name and count with your variable back end name where you want to store the count
sum = parseInt(sum)+parseInt(rows[i].your_field_name_to be_summed)
in the above line just replace your_field_name_to be_summed with your field name where your count values to be summed are stored
api.controller=function($scope,$rootScope) {
/* widget controller */
var c = this;
$rootScope.$on("field.change", function(evt, parms) {
var g_form = $scope.page.g_form;
if(parms.field.name=="testing") // replace testing with the your MVRS internal name
{
var rows = JSON.parse(g_form.getValue('testing')); // replace testing with the your MVRS internal name
var sum=0;
for(var i=0; i<rows.length; i++)
{
sum = parseInt(sum)+parseInt(rows[i].your_field_name_to be_summed) // replace your_field_name_to be_summed with your field name where your numbers to be added are stored
}
g_form.setValue('count',parseInt(sum)); // replace count with the variable back end name where you want to store the count of the MVRS rows
}
});
};
2)Then go to your catalog item and create. variable type called "custom" and tag your widget like below in widget field
Then try adding the rows and giving the number in the field and see if its working
Hope this helps
please mark my answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 12:32 PM
alert('JSON'+rows);
JSON[object Object]
alert('Length'+rows.length);
Length1
alert(sum);
NaN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 12:35 PM
can you post a screenshot of the MVRS row once you add it and also which type of field is hours 1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 12:43 PM
I have got it working now there was some syntax error.
Just one question though, I have 2 fields inside MRVS hours & hours1 and two fields outside MRVS i.e. total_hours and total_hours1.
So will i have to create another widget and variable to populate 2nd field or it can be achived in the same widget?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 12:48 PM
Hope this helps
please mark my answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 12:52 PM