need help in calculations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 09:53 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 10:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2024 11:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:17 AM
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/