Answered

Set_VAR is not performing arithmetic opertaion

I provided Get_webvalue = number 1

Get_webvalue=number 2

set_VAR= @number1+@number 2.

 

I am not getting the answer when I add @number 1+@number 2. I am using static beacuse expression is gving me error as illegal expression. Please help me on this

 

0
22 comments
Avatar
Zach Schwantes

Hello,

From my understanding to use some sort of arithmetic expression, where you are adding two variables, you would have to use the expression option rather than creating a static variable. I saw your other posts mentioning you want to add two numbers that look may be in the format of $25,000, and such like currency format. The only way I can think of this reasonably being executed within Subject7 is by stripping both numbers with special characters (either use Java Script or if you are using get_web_value function already use "\D+" in the characters to exclude non-digits. Then you would use some sort of Java Script that would take the third variable of the total and make it into the format you want with the proper "$" and ",". If you have any other questions, feel free to reach out on this public forum!

EX:

0
Comment actions Permalink
Avatar
Zach Schwantes

Hi,

Below I have attached the Java Script code you would need to pass this "Total" variable through, the end format, along with what the step looks like.

Thanks for your time, and I hope this resolves your issue.

const price = @Total;

var test1 = price.toLocaleString('en-US', { style: 'currency', currency: 'USD'});

return test1;
0
Comment actions Permalink
Avatar
Prasanna Lakshmi

I tried with Get_webvalue comands excluding special characters, but the result is coming as number 1= NaN, so i switched my idea to javascript in the javscript I see set @ number 1 = ( just empty). please help me on this issue

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Prasanna,

Would you please provide us sample values that you retrieve using Get_web_value ?

Zach, thank you so much for jumping in :) 

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

@joseph Thank you so much for all the help. 

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

@subject 7 Team - Can we perform division arithmetic operation using subject 7 platform ?

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

@subject 7 Team - Can we perform division arithmetic operation using subject 7 platform ? @Joseph Hamdan@Zach Schwantes. please help me 

0
Comment actions Permalink
Avatar
Rex Feizi

Prasanna, 

Would you please give us some context and a more high-level description of what is your main scenario? It'll help us give you better advice.

But if you're just looking for how to do division, it's pretty much "x / y". I’ve popped in a screenshot as an example that shows you how it can be done. 

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

@Rex Feizi sure. I want to divide $345.67/4 using Subject 7 ? Does Subject 7 support such type of arithmetic operations with dollar and comma and decimal values ?

0
Comment actions Permalink
Avatar
Rex Feizi

Where are you reading this value from? Can you describe your scenario? For example, you can say something like " I want to read 2 values from a web page and then do a division by 4" etc. 

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

It is a balance amount($ 345.67/4 )and I need it to divide it by 4.  As of now I have only one balance amount . Can you please help me with this ?

 

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

It is a balance amount($ 345.67/4 )and I need it to divide it by 4. Here number 4 is not a webvalue, that balance amount should be divided among 4 quarters.  As of now I have only one balance amount . Can you please help me with this ?

0
Comment actions Permalink
Avatar
Rex Feizi

I understand you want the sum to be divided by 4.

My question is where are you reading this sum from? Are you reading from a webpage or a database? If you read it off a webpage, then we can trim the sum to be a number and divide it.


0
Comment actions Permalink
Avatar
Prasanna Lakshmi

Thank you so much for all your help. I am reading it from a webpage , and should the dollar and comma be excluded while setting up a set_var command ? @ Rexfeizi

0
Comment actions Permalink
Avatar
Rex Feizi

No worries. If you're pulling a number from a web page, just like Zach did in his post, you can use "\D+" to get rid of any letters or symbols so you're left with just the number. Let's say this number goes into a variable we'll call sum.

Next step is to do something with this number. You want to divide it by 4 and keep the result. You can make a new variable for this in your code. We'll name it result. You do this with a command called set_var, and you tell it to use an "expression" to do the math – just type in @sum/4 (look at the example I put above to see how it's done).

Here's a quick recap:

  1. Use get_web_value to read the sum from the webpage. When you do this, use "\D+" in the 'Characters to Exclude' field to make sure you only get numbers (be careful with uppercase and lowercase – \d and \D are not the same).

  2. Set up a new variable named result using set_var. For the Source Type, pick "expression". Then, in the value box, you're going to write @sum/4.

  3. Now, result is the new variable that has your sum divided by 4.


Hope this helps. 

 

0
Comment actions Permalink
Avatar
Zach Schwantes

Hi Prasanna, 

Thanks for reaching out!

There are many ways you could do a "check" in Sub7 due to its wide range of capabilities. This sort of depends on what you are looking for along with the capabilities of the side we are attempting to easily extract the data from. In this case, you could either get_web_value of that next period's value we want to check and then name it WebSumVar (you can follow any naming convention). With this, you can use an IF function, Contains function, or even a Compare function depending on what you are all wanting to do with this information. My recommendation to you, is to use the Contains function in which you can search a source variable with a static or dynamic value. If that particular value fails, the script is halted immediately. Attached below, are links with some descriptions and screenshots of how these various functions work. Please review thoroughly to determine what suits best for your use case. Thanks!

"COMPARE" Command - Subject7 - Confluence (atlassian.net)

"CONTAINS" Command - Subject7 - Confluence (atlassian.net)

"IF" Command - Subject7 - Confluence (atlassian.net)

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

@Zach Schwantes I want to subtract (96, 789.11-6,913.51= 89,875.60)  for Q3 and for Q4 I should subtract ( 89,875.60-6,913.51= 82,962.09) and so on.. please help me how should i work on this ?

0
Comment actions Permalink
Avatar
Zach Schwantes

Hi, I'd assume these are all going to be in different variables. I do not quite understand the use case here, what are we planning to do with the result of these numbers. I would suggest possibly using the SET_LIST function to record these values and then possibly writing to a Share Point file or .xls or .csv file. 

Num_1 = 96,789.11

Num_2 = 6,913.51

Var_total1 = 89,875.60 (Num_1 + Num_2)

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

Hi , 

 

Here there are trying to verify the payments and balances. We need to verify the payment and balance for each quarter. so how to write this flow calculating( subtracting) payment and balances ?

0
Comment actions Permalink
Avatar
Zach Schwantes

Hello,

Please explain what we are attempting to do with this calculated data? Depending on the rows set up on this site, you may be able to use the loop index + a set var for it to continue to loop and calculate this data properly without stopping. That being said, where are you wanting to store this data? We need some way to input this data into an organized manner so you can reference this once the script is complete. Personally, I'd recommend either writing it into a a list or write to Share Point file. 

0
Comment actions Permalink
Avatar
Prasanna Lakshmi

Hi Zach,

I have used this  loop to verify  the above  payments and balances. But where should I verify the result  using subject 7 ? How to return the result in subject 7 ? Please help me .

var startingBalance = 96789.11; // Starting balance
var quarterlyPayment = 6913.51; // Quarterly payment
for (var quarter = 1; quarter <= 8; quarter++) { 
    if (quarter >= 3) { 
        startingBalance -= quarterlyPayment; // Deduct the quarterly payment from Quarter 3 onwards
        } 
    } 
    console.log("Final payment amount after 8 quarters: $" + (96789.11 - startingBalance).toFixed(2));

 

 

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Prasanna,

I did a small modification to your JS snippet. Please use the below in Get_Web_Value with JavaScript option:

var startingBalance = 96789.11; // Starting balance
var quarterlyPayment = 6913.51; // Quarterly payment
for (var quarter = 1; quarter <= 8; quarter++) { 
   if (quarter >= 3) { 
       startingBalance -= quarterlyPayment; // Deduct the quarterly payment from Quarter 3 onwards
       } 
   } 
var finalResult = "Final payment amount after 8 quarters: $" + (96789.11 - startingBalance).toFixed(2);
return finalResult

Regards,
Subject7 Team

0
Comment actions Permalink

Please sign in to leave a comment.