How to trigger function or client script the when delete the multi row variable set records

ramesh_r
Mega Sage

Hi All,

 

I want to trigger a function or client script when deleting the multi-row variable set records

 

ramesh_r_0-1693471314881.png

 

Thanks

 

5 REPLIES 5

Brad Bowman
Kilo Patron

This post may help give you an idea of how you can 'watch' the MRVS for changes.  In this case you might have to update a hidden variable on the Catalog Item when this triggers, then use an onChange Catalog Client Script when that variable changes.

 

https://www.servicenow.com/community/itsm-forum/populate-field-outside-mrvs-with-a-total-sum-of-fiel... 

@Brad Bowman  

 

I write the below script but its not triggering when i remove the records from mrvs

  /* widget controller */
    var c = this;
    $rootScope.$on("field.change", function(evt, parms) {
        var g_form = $scope.page.g_form;
        if (parms.field.name == "test_value") // replace testing with the your  MVRS internal name
        {
            if (g_form.getValue('test_value')) {
                var rows = JSON.parse(g_form.getValue('test_value')); // replace testing with the your  MVRS internal name
                var sum = 0;
                if (rows.length > 0) {
                    for (var i = 0; i < rows.length; i++) {
                        sum = parseInt(sum) + parseInt(rows[i].name) // 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
                }
            }
        }
    });

Ankur Bawiskar
Tera Patron

@ramesh_r 

you can detect the add/remove action

check this link

MRVS detect when a row is removed or deleted 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

 

I wrote this below script in the widget its works only when the record is added but not trigger when i remove the records from mrvs

 

api.controller = function($scope, $rootScope) {
    /* widget controller */
    var c = this;

    $scope.$watch(function() {
        return $scope.page.g_form.getValue('test_value');
    }, function(value) {
        var data = JSON.parse(value);
        $scope.page.g_form.setValue('count', data.length);

    });

};