Set value of a field, from a field in a MRVS

Facundo Prado
Tera Expert

Hello everyone!!
I have this field on the Form (Payment reference). with this MRVS (Booking details):

FacundoPrado_0-1709754282673.png

I need to populate in the "payment reference" field, with the value of "total expense" from MRVS.

I´ve tried with a onSubmit client script applied to a Variable set, but is not working.

If you have some idea i´ll appreciate.

Thanks!

 

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

I have never tried it. But this thread could help you.

https://www.servicenow.com/community/developer-forum/how-to-calculate-the-total-of-variables-into-an...

 


Please mark this response as correct or helpful if it assisted you with your question.

Saloni Suthar
Mega Sage
Mega Sage

Hi @Facundo Prado ,

Please share your script.


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

SCRIPT INCLUDE:

 

var mpr_booking_details = Class.create();
mpr_booking_details.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getBookingDetails: function() {
        var booking = this.getParameter('u_grand_total');
        var grBooking = new GlideRecord('x_amspi_manual_p_manual_payment_request_tool');
        grBooking.addQuery('u_grand_total', booking);
        grBooking.query();

        if (grBooking.next()) {
            var results = {
                "grandTotal": grBooking.getValue('u_grand_total')
            };
            return JSON.stringify(results);
        } else {
            return 'No trajo nada';
        }
    },

    type: 'mpr_booking_details'
});




---------------------------------------------------------

CLIENT SCRIPT:

function onSubmit() {
    alert('Before GlideAjax');
    var ga = new GlideAjax('mpr_booking_details');
    ga.addParam('sysparm_name', 'getBookingDetails');
    ga.addParam('u_grand_total', g_form.getValue('u_grand_total')); // Pass the grand total value as a parameter
    ga.getXMLAnswer(getGrandTotal);
}

function getGrandTotal(answer) {
    if (answer) {
        var data = JSON.parse(answer);
        alert('Grand Total: ' + data.grandTotal); // Use '+' to concatenate strings in JavaScript
    } else {
        alert('No data found.');
    }
   
alert('After GLideAjax');
}

Amit Verma
Kilo Patron
Kilo Patron

Hi @Facundo Prado 

 

Please have a look to my answer on the below post for your requirement :

https://www.servicenow.com/community/developer-forum/adding-total-from-multirow-variable-set/m-p/277...

 

You can also check below link:

https://www.servicenow.com/community/now-platform-forum/calculating-totals-from-mult-row-variable-se...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.