- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 06:03 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:32 AM - edited 11-29-2022 07:35 AM
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
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:56 AM - edited 11-29-2022 07:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:32 AM - edited 11-29-2022 07:35 AM
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
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:41 AM
sorry to ask, i am new to this.
i created the widget here
where do i go to create the variable of type custom?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:46 AM - edited 11-29-2022 07:50 AM
@Peter Williams No problem i will guide you
First thing you need to do is delete the widget that you have created and create a new widget under service portal module.You have created it under system widget which will not work
Open the widget module under service portal and click on new and then place the entire script in the client controller field .Remove the existing script in the client controller and copy the script that you wrote in the system widget
Just type in maintain items in the left navigator and open your catalog item
Then open your catalog item by searching your catalog item name and then scroll down to variables related list
Then click on new button to create a new variable and then select the type as custom as shown below and add your widget in the widget field under type specifications tab
hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:50 AM
@Peter Williams edited the above answer please check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:53 AM
got it all added.
question, will this only work in the Service Portal for Catalog it or with Record Producers?