The CreatorCon Call for Content is officially open! Get started here.

How to Update the Total on the SP order status page from an RITM Variable

Peter Williams
Kilo Sage

Good day everyone,

 

i am looking to update the Total field on the ServiceNow Portal Order status page with an RITM variables from different forms.

 

Basically, i have created some expense forms on the sc_req_item. These forms have different variables names for the totals they are submitted 

I would like to have those totals to be displayed on this page when they submit their forms

 

PeterWilliams_0-1707150291833.png

 

One way i was thinking is to update the price field on the sc_req_item with the fields on the form with a client script

 

function onSubmit() {
  var totalCost = g_form.getDecimalValue('total_cost');
  var totalConf = g_form.getDecimalValue('total_conf');

  total = totalConf + totalCost;

  g_form.setValue('price', total);
   
}
 
but that didnt seem to work
 
any other suggestions on how i can do this please?

 

1 REPLY 1

Swarup Patra
Kilo Guru

To update the Total field on the ServiceNow Portal Order status page with RITM variables from different forms, you can follow these steps:

1. Identify the variables: Identify the variable names from the different forms that you want to display in the Total field.

2. Create a Business Rule: Create a business rule on the sc_req_item table that triggers on insert or update. This business rule should calculate the total from the different variables and update the Total field.

Sample code for the business rule:

javascript
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
var total = 0;
total += gr.variable_name1; // replace variable_name1 with your variable name
total += gr.variable_name2; // replace variable_name2 with your variable name
// add more variables as needed
gr.total = total; // replace 'total' with your Total field name
gr.update();
}
})(current, previous);


3. Update the Portal Page: Update the Service Portal page to display the Total field. This can be done by modifying the HTML template or the AngularJS controller for the page.

4. Test: Test the solution by submitting different forms and verifying that the Total field is updated correctly on the Order status page.

Please note that this solution assumes that you have the necessary permissions to create business rules and modify Service Portal pages. Also, the variable names and the Total field name in the sample code should be replaced with your actual field names.


nowKB.com