I want to get a variable from MRVS, but the value does not appear in the TASK table!

Daemon5
Tera Expert
Hi!
I have a client script that retrieves the variable "subtotalamount" in MRVS, adds up the number of rows in it, and adds it to the variable "u_totalamount" so that it will be displayed after submission.
In the configured Console Log, the u_totalamount value is calculated correctly, but when I look in the corresponding value in submitted TASK, there is nothing in it.
Are there any improvements or settings I should review?
Here is the script.

 

function onSubmit() {
    var totalAmount = 0;
    var gr = JSON.parse(g_form.getValue('name_of_mrvs'));

    for (var i = 0; i < gr.length; i++) { 

        var subtotal = gr[i].subtotalamount;

        var subtotalNum = parseFloat(subtotal);
        if (!isNaN(subtotalNum)) {
            totalAmount += subtotalNum;
        } else {
            console.log('Invalid number at row ' + i); 
        }
    }

    console.log('Calculated Total Amount:', totalAmount);  // Console Log

    // Populate result in u_totalamount
console.log('Setting u_totalamount to:', totalAmount);  // Console Log
    g_form.setValue('u_totalamount', totalAmount);
    console.log('u_totalamount set successfully'); // Console Log
};

 

1 ACCEPTED SOLUTION

Daemon5
Tera Expert

Sorry, I solved it myself.
This script was running correctly.

View solution in original post

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

What do you exactly mean with corresponding value in task? Do you have a field added on task? Or are you quering task.variables.your_variable?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Daemon5
Tera Expert

Sorry, I solved it myself.
This script was running correctly.