Combining UI Macro with Widget in Service Portal to calculate a Multi Row Variable Set

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 12:00 PM
Hello,
I have a record producer that needs to show our end users a total amount for their requested reimbursement. We have a Multi Row Variable Set in place to allow the user to enter one item at a time. I've added a UI Macro to the Record Producer and linked it with a Widget so it will show up on the Service Portal.
What I'm having a very difficult time with is clicking my button and getting the widget to calculate a total and return any info. Any info I need to provide, I'm willing to do so. Also, this is within a Scoped Application which I know complicates things a bit.
Thanks in advance!
Here's my HTML info. The funding_sources is my MRVS variable name.
<div>
<button ng-click="confirmTotal(funding_sources);">Calculate Total</button>
</div>
Client Script info. The total: amount refers to the name of my variable within the MRVS that holds the user's dollar amount.
// This is the confirmAsset method on your controller
this.confirmTotal = function(funding_sources) {
// Asset is being bassed from the ng-click
// The controller has a server property with a method called get on it.
// The object you pass to the get() call is passed as "input" on the server-side code.
this.server.get({
// NOTE: This method property is totally unneeded technically.
// I am adding it here so that my server-side code can know exactly what it's supposed to do.
method: "confirmTotal",
total: amount
});
}
Server Script info. This is currently working in an onSubmit functionality to validate the user's total one last time before submission. As part of requirements, I must present a total on screen for the user before they submit their request.
if (input) {
// Adding a method here just in case anything else sends information to the
// client side script, we can distinguish and only handle what we need to.
if (input.method === "confirmAsset") {
if (input) {
// Adding a method here just in case anything else sends information to the
// client side script, we can distinguish and only handle what we need to.
if (input.method === "confirmTotal") {
var total = 0;
var srcObj = (g_form.getValue('funding_sources').length != 0) ? JSON.parse(g_form.getValue('funding_sources')): [];
for (var i = 0; i < srcObj.length; i++) {
total += parseFloat(srcObj[i]['amount'].replace('$', '').replace(/,/g, ''));
}
var decimal, decimalValue, formattedValue, outputString, value, signValue, element, amount;
var currencySign = "$";
total = total.toString();
//CHECK FOR DECIMAL VALUE
if(total.indexOf('.') > -1){
decimal = total.split('.');
if (decimal.length > 2) {
decimalValue = decimal[1] + '.' + decimal[2];
}
else if (decimal[1].length == 0) {
decimalValue = '00';
}
else if (decimal[1].length == 1) {
decimalValue = decimal[1] + '0';
}
else {
decimalValue = decimal[1];
}
value = decimal[0];
}
else {
value = total;
decimalValue = '00';
}
//CHECK FOR CURRENCY SIGN
if (total.indexOf(currencySign) > -1){
signValue = value.split(currencySign);
if (containsSingleValue(signValue[1], ',')) {
element = signValue[1].split(',');
amount = getAmount(element);
}
else {
amount = signValue[1];
}
}
else {
if (total.indexOf(',') > -1) {
element = value.split(',');
amount = getAmount(element);
}
else {
amount = value;
}
}
//RECONSTRUCT VALUE WITH PROPER FORMATTING
var length = amount.length - 1;
var count = 0;
//amount = removeLeadingZeros(amount);
for (i = length; i >= 0; i--) {
if (i == length) {
formattedValue = amount.charAt(i);
}
else if (count % 3 == 0 && i != length) {
formattedValue = amount.charAt(i) + ',' + formattedValue;
}
else {
formattedValue = amount.charAt(i) + formattedValue;
}
count++;
}
outputString = currencySign + formattedValue + '.' + decimalValue;
if (total){
return confirm('Please confirm this is the total amount of reimbursement: ' + outputString);
}
else{
alert("You must enter at lease one funding source in order to submit.");
return false;
}
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 12:14 PM
Server script can't use g_form (see g_form.getValue('funding_sources')). You can't use any client functions in the server code (see usage of confirm and alert). You should get the information on the client side and include it as additional property of object, which you use as parameter of c.server.get. The property will be available on the server side as properties of input object.
Probably you can Implement all calculations on the client side (inside of the code of confirmTotal method). At least I don't see any requirements for server side calculations.