need help in calculations

tanz
Tera Expert

I have a tabel that capture details by calculating the total qty

 

HP  Total qty : 1  ID: 1     DOP: 5th July Toatl amount:20

laptop  Total qty: 2   ID:2   DOP: 5th July   Total amount: 40

laptop Total qty: 3   ID:3   DOP: 6th July   Total amount: 60

All lets says are stored in RITM0001 in a tabular format.

Now I want to push the amount data in table with separate details:

 

HP        1     1    5th July   20 RITM0001

laptop   1   2  5th July 20 RITM0001

laptop    1   2   5th July   20 RITM0001

laptop     1   3   6th July   20   RITM0001

 

and so on, these fields are are item details, individual qty , id, date of purchase , separate amt and ritm no. Out of which i already have the details stored for item details, individual qty , id, date of purchase  and ritm no , i am trying to populate the individual amount for each device from the total amount calculated and trying to populate the correct values against each item. I have tried to do the script and i was able to get the details of the total qty and total amount in while loop. Now how can I figure out in which record which figure should go. Can someone help with the scripting for this

3 REPLIES 3

Mark Manders
Mega Patron

Can you share your script? That may help in understanding what it is you want to achieve, because it's not really clear what you are asking.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

gs.info(amt + qty);
var out_table = outtable1.updatetax(ritm, Amt, TotalQty);
 
in here im getting the total qty in logs:
1   20
2    60
but this mapping should happen, its taking the first value and updating it, my out table has all the details i only need to populate the correct segregated amt based on which asset it should go to
 
update: function(tableSysID, Amt,TotalQty) {
        var out_table = new GlideRecord('u_outbound');
        out_table.addEncodedQuery('u_ritm=' + tableSysID);
        out_table.query();
        while (out_table.next()) {

           out_table.u_ind_amt = amt / totaqty;
            }
            out_table.setWorkflow(false);
            out_table.update();

        }
        return true;
    },

Ravi Gaurav
Giga Sage
Giga Sage

Hi @tanz 
It guess you're trying to distribute the total amount among individual items based on their quantity.

As per the script shared possible solution look like this :-


function(tableSysID, Amt, TotalQty) {
var out_table = new GlideRecord('u_outbound');
out_table.addEncodedQuery('u_ritm=' + tableSysID);
out_table.query();

var amountPerUnit = Amt / TotalQty;

while (out_table.next()) {
var individualQty = out_table.u_individual_qty;
var individualAmt = amountPerUnit * individualQty;
out_table.u_ind_amt = individualAmt;
}
out_table.setWorkflow(false);
out_table.update();

return true;
}

Please go ahead and test the script. If you encounter any issues or have further questions, feel free to ask. I'll be happy to help you troubleshoot or refine the script as needed.

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


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/