Add 8 new fields, 4 (where you compare data: dType.subVal1 equals to OptionA, and dType.subVal2 equals OptionB). The other 4 fields (where you will insert your dynamic "do a search for "⦠for a1, a2 and b1, b2)
And create one āreturned valuesā field that will be used to return the result (val3) and will be accessible after the workflow by step x ⦠result:
let val1 = properties.val1;
let optionA = properties.option_a;
let val2 = properties.val2;
let optionB = properties.option_b;
let search_a_1 = properties.a_1;
let search_a_2 = properties.a_2;
let search_b_1 = properties.b_1;
let search_b_2 = properties.b_2;
if (val1 == optionA) {
a = search_a_1;
} else {
a = search_a_2;
}
if (val2 == optionB) {
b = search_b_1;
} else {
b = search_b_2;
}
let result = a + b;
return {
result: result
}
Optionally you can skip the lines from 1 to 11 where the values of the searches are being declared. You can use the properties.xx directly in the code (but I think itās easier to read and modify this way).
@yusaney1 has presented a solution. The solution however involves creating a custom plugin which I believe is quite a bit of overhead and work to just to add the logic you presented in your question.
Iām sure there is a purely Bubble solution that someone could present. The part that is a bit tricky to work with in Bubble presently is combining pieces of logic. Coming from a technical background, as you seem to be having presented Python code, one of the first plugins I add to every project is the āToolboxā plugin. The toolbox plugin allows us to inject javascript into our Bubble app as needed. A small amount of scripting, in the right places, can go along way to creating workflows that are not convoluted with Bubble āwork aroundsā.
Keep in mind, the entire point of using Bubble is to write as little code as necessary. In other words, try to implement as much logic as you can within the Bubble workflows.
With that being said, I would use a combination of āonly whenā workflow logic and a small bit of Javascript, using the āServer Scriptā action from the Toolbox plugin, to accomplish your goal.
Here is an example setup of how to use only when and get a property value from an object.
What is happening inside of that Node script box, Iāll mostly leave for you to search the forums and do some reading. However, as it pertains to this question, you will need to understand how to grab the property from your object. Bubble basically stores the properties as the field name, suffixed by the property type. So my person data type has a field named age and it is defined as a number, hence āpersons[0].age_numberā. However, if you want to be sure of the properties on your data type you can always send the properties out to a text object on your page for debugging using JSON.stringify(persons);
Finally, you can chain these together to create the logic you need above using the "Result of previous step like this:
Thank you @yusaney1
I was trying to avoid using a plugin because, if I was going to use a plugin, Iād want to just develop one that allows no-coders to do this kind of work but that level of plugin development on bubble is above my head (let alone outside of my available free time for coding projects).
Then I would go for a solution involving for example a Server script from @mishav Toolbox plugin as @bubble.trouble suggested, maybe with a different approach.
Thank you @bubble.trouble
Iām going to wait to see if someone has a non-code version of what I want to do. If I donāt get any no-code answers, Iāll do it in code. Thank you for your reply. I definitely have Toolbox installed as I do a lot of other tweaks that canāt be done in the no-code environment.
When you say expression1, expression2 etc. are you referring to conditions that would apply to a search?
i.e. with if(dType.subVal1 == OptionA) { a = do a search for (expression1) }else { a = do a search for (expression2) } you are just looking to set a to one of two possible values, dependent on OptionA's value?
Same for b. And then you want to add them?
You should be able to handle that with a single expression in Bubble, no states required (which would be an issue on the backend). This is what I would do:
Test for your condition with an expression that resolves to true / false (yes / no in Bubble)
Format that as text
Place your Searches in the Yes / No sections
Convert the text resolution of that Boolean to a number
@exception-rambler
Thank you for your reply. Unfortunately, thereās an āIFā that comes before the option to format as text, which didnāt allow this as an option. Bubble needs to add if statements to their conditions and it will resolve this. For now, I went ahead and deployed the solution on a backend DB trigger that watches the parameters used to determine the outcomes of my pricing and then uses javascript to output a list of values, which I then assign in a second action.
Hereās my code:
var insType = āMedicaid / Soonercareā;
var appType = āLocalā;
var stateFullFiling = 104.3;
var stateDiscFiling = 22.5;
var marketplaceBaseFee = 80;
var remoteBaseFee = 75.7;
var docMarketPay = 20;
var localRemoteAppFee = 20;
// Above this line are input variables into the script in case you want to test the code ( I have ) outside of Bubble. I don't get errors outside of bubble.
// Below this line is the full script copied to the table
var stateFee = 0;
var filingFee = 0;
var paymentAmount = 0;
var ccFee = 0;
var pay4Doc = 0;
if (insType === ""){
stateFee = stateFullFiling;
}else{stateFee = stateDiscFiling;}
if (appType == "Marketplace"){
filingFee = marketplaceBaseFee;}
else{ filingFee = remoteBaseFee;}
paymentAmount = stateFee + filingFee;
ccFee = Math.round(((paymentAmount * 0.029 + 0.30)) * 100) / 100;
if (appType == "Marketplace"){
pay4Doc = docMarketPay;}
else{
pay4Doc = Math.round((paymentAmount - stateFee - ccFee - localRemoteAppFee) * 100) / 100;
}
var rList = new Array();
rList[0] = paymentAmount;
rList[1] = ccFee;
rList[2] = pay4Doc;
console.log(rList[0] + ", " + rList[1] + ", " + rList[2]);
return rList;
Unfortunately, Iām getting āinvalid return statementā in the logs.
@john30 that should be working based on what youāve posted. The only piece that might be throwing it off is Bubble is not 0-indexed. Youāre results should really be item #1, item #2, item #3.
No values are available:
It should say paymentamount = ā¦
Without a return statement telling the software which variable to send back, how does it know? Iām guessing without āreturn ā¦ā, we are doing all the work and then no values are being passed back, which is why the resultsList() is empty.
The IF is captured in that first expression - you are then evaluating the truthy & falsey outcomes of that IF via the format as text. Itās a weird syntax because you lead with your test, not with an IF.
So to summarise, you can use any expression that resolves to true / false, followed by :formatted as text as a Bubble equivalent of IF
Hi @bubble.trouble ! First, I want to thank you for helping me figure this out. I see it works in your example. The only difference I see in your code versus mine is that you pass your data to a state and I, being a backend workflow, pass my data to a datatype. Iām still unable to see any data coming out of the script though.
Are you available to connect remotely with me? I can pay you. If so, send me an email and weāll use Teams or Zoom to connect.
@exception-rambler I wish I could find the documentation on all of the syntax needed for using this. Iāve replaced the script with only creating an array and sending it back and that works, so I now know that thereās a problem with my script.
When I run my script outside of bubble, it works, so the problem is definitely, now, where youāre helping me: getting the keyvalue pair data. Hereās my updated script that is still not returning the data:
I posted an edit above - that should sort you out.
Or, revert to vanilla Bubble which is always better where possible. Living across two worlds (which I do with my platform) is the headache you donāt need unless thereās no alternative.