Creating Expense Request using MRV

Peter Williams
Kilo Sage

Good Morning everyone,

i am task to create an expense request form in ServiceNow and have decided to use the MRV for the expense line items.

But one of the requirements is to get the total item cost listed on the form as they are entered into the MRV.

What is the best approach for this?

 

PeterWilliams_0-1669730563946.png

 

2 ACCEPTED SOLUTIONS

Mohith Devatte
Tera Sage
Tera Sage

Hello @Peter Williams ,

IF you want to do it on change of the MVRS then i can suggest you a solution which i used in my requirement and it worked for me .But its bit a lengthy process but we can do .

 

Follow this process step by step :

1)You need to handle this via hidden widgets on the record producer 

create a widget with this code 

 

api.controller = function($scope) {
    /* widget controller */
    var c = this;
var g_form = $scope.page.g_form;
    $scope.$watch(function() {
        
        return g_form.getValue('your_mvrs_internal_name');
    }, function(value) {
        if (value) {
            var jsonData = JSON.parse(value);
         
            var total = 0;

            for (var i = 0; i < jsonData.length; i++) {
 
                total=total+parseInt(jsonData[i].your_cost_field_name_inside_mvrs);
            }

            //Set Value in the total field
          g_form.setValue('total_cost_field_name_outside_mvrs', total);
        }
    });
};

 

 

2)After this create a Variable of type Custom and add the Widget  in the widget field like below 

Screenshot 2022-11-29 at 21.00.31.png

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

 

 

View solution in original post

@Peter Williams

This will work for both service catalog and record producers in service portal 

 

also  just FYI  this will work only for service portal but in order to make it work for native view then we might have to do some jelly scripting in macro and add that macro above the widget field in the same variable

Hope this help 

Mark the answer correct if this helps you 

Thanks

 

View solution in original post

13 REPLIES 13

@Peter Williams

This will work for both service catalog and record producers in service portal 

 

also  just FYI  this will work only for service portal but in order to make it work for native view then we might have to do some jelly scripting in macro and add that macro above the widget field in the same variable

Hope this help 

Mark the answer correct if this helps you 

Thanks

 

This is Totallly Amazing, 2 years trying to figure this out and it work

Nope the users will only need to do this in the Portal and not Native

 

PeterWilliams_0-1669737639258.png

 

 

 

Thank you, Thank you, Thank Youuuuu

one thing i noticed, it doesnt handle decimals 

when i type in 43.50, it will round to 43

 

PeterWilliams_0-1669751167631.png

 

i tried parseInt(total).toFixed(2) and also what you see above and it didnt work

 

 

PeterWilliams_1-1669751233880.png

 

By definition, parseInt is going to grab an integer from a value.  If you're introducing the possibility of decimals, then use parseFloat instead which will grab the number, with any decimals, no rounding unless you add .toFixed(2)