Divide two values in bigcommerce - handlebars.js

does anyone know if it's possible to divide two values?
For example:
product price / unit price = wanted result
Product price:
{{price.without_tax.formatted}}
A filter for unit price
{{#filter custom_fields 'Units per case' property='name'}}
<p>{{ value}}</p>
{{/filter}}
If I am to use something like:
{{#filter custom_fields 'Units per case' property='name'}}
<p>{{toFixed price.without_tax.formatted divide value}}</p>
{{/filter}}
I get a 0. If I don't include toFixed then nothing shows up. Not sure how to proceed. Please help.
(I know this is some crazy code but I don't know better.)

I'm seeing a number of issues. Try this:
{{#filter custom_fields 'Units per case' property='name'}}
<p>{{toFixed (divide ../price.without_tax.value value) 2}}</p>
{{/filter}}
Use price.without_tax.value instead of price.without_tax.formatted so it returns a number instead of a string.
Add ../ to the price object since it is nested inside {{filter}}.
The divide syntax is {{divide a b}}.
I added a parameter "2" to {{toFixed}} so it shows the result with 2 decimal places.

Related

Display cumulative value of each column in balloon text

I built a cumulative line graph using context.cumulativeCol() in the Value field and I am interested in displaying the cumulated value of the current column in the ballon text.
This is what I have, which only shows the value of the column:
I tried to change the default value [[Row]], [[Column]]: [[Value]] from the Ballon Text field and tried to use something like context.cumulativeCol() but I could not achieve my goal.
If it is possible, how am I supposed to do it?
I've just tried to put:
return "Cumulative: " + context.cumulativeCol();
to the balloon function and it worked fine in the latest version. Perhaps you are trying to return a number instead of a string from the balloon function?

How can I format a time variable to include colons? (JDE Event Rules)

I'm trying to create an ER that adds colons to my time variable in JDE (OMW). I've tried using the substring function to make 3 substrings and then add a colon inbetween each substring, but that doesn't seem to be working for some reason.
Here is what I tried to do as a test to see if the substring would work.
substr([PC Time - Last Updated (F0911) (UPMT)],0,2 )
This should cut my time from an 8 digit number to a 2 digit number, but it doesn't seem to be doing anything. Any ideas? Currently this line of code is in the DO section of my event rules.
You can achieve what you want using the substr function. But you will have to give the function your time. From your code, i can see you used a "PC" variable.
substr([PC Time - Last Updated (F0911) (UPMT)],0,2 )
Which relate to the previous value inside the business view. Maybe you wanted to use a "BC" one? Because the first record will always be null for a "PC" variable Inside a DO SECTION event rule. Just make sure you are sending a value to the substr function.

Edit a data item in Cognos to display as two digits

Disclaimer: I am a Cognos newbie.
I want to format a data item in Cognos (Report Studio 10.2) to always display as 2 digits. For example, if the value of the data item in 2, I want it to be displayed as 02. How can I achieve this?
I have tried
Format$([my_data_item], "00")
Format([my_data_item], '00') - w/o the dollar sign
None worked.
Any help will be highly appreciated. Thanks!
Marcus ...thanks for pointing me in the right direction.
I was able to use the round function in the query with a CASE statement and it served my purpose with very little modification to the original report. Note to any new Cognos developer would be leave formatting to the report page and not the query.
case when [TRANSFORMATION VIEW].[SOME_FACT].[DOLLAR_VAL]<>-99999 then
case when [TRANSFORMATION VIEW].[SOME_FACT].[DOLLAR_VAL] >= 1000000 then
round( [TRANSFORMATION VIEW].[SOME_FACT].[DOLLAR_VAL] /1000000, 2)
else
round([TRANSFORMATION VIEW].[SOME_FACT].[DOLLAR_VAL],0)
end
end
Then on the report itself, I formatted the data item as Numeric and didn't change any of the default settings. That did the magic. The reason why I have round([TRANSFORMATION VIEW].[SOME_FACT].[DOLLAR_VAL],0) is because I don't want to display cents in the dollar amount.

"Variable variable" syntax

This is a question related to getting Drupal CCK fields (just in case that happens to change anything).
I have several Drupal CCK fields with similar names. They have the same name with a number at the end. that I'd like to pull values from these fields (ten fields total). This is the syntax for accessing the fields values:
$node->cck_field_1[0]['value']
$node->cck_field_2[0]['value']
$node->cck_field_3[0]['value']
…etc.
Since they're all separate fields, but they're numbered, I'd like to just loop through incrementally to write out what I need (there's a lot more to what I'm writing than just accessing these fields' data, but they're the determining factors of the rest), but I can't figure out how to insert a variable into that part of the code.
e.g., (if $i were the incremental number variable), I'd like to be able to write the following string as a variable:
'$node->cck_field_' . $i . '[0]["value"]'
I understand about using the curly brackets to create a variable name from a string, but the part I need the variable in needs to be outside of the string. e.g. this works:
${node}->cck_field_1[0]['value']
but this doesn't:
${node->cck_field_1}[0]['value']
(so I can't write ${'node->cck_field'.$i}[0]['value'] )
So how can write this so that I can use $i in place of the number?
This should work:
$node->{'cck_field_' . $i}[0]['value']

odbc_result_all formatting

$selectVolID = "Select COUNT(VolunteerID) from planetVolunteers";
$getVolID = odbc_exec($connect, $selectVolID);
echo odbc_result_all($getVolID);
gives:
Expr1000
49
1
49 is the correct count. I want to change the Expr1000 to something legible and get rid of that 1 (which i assume means there are no more values to count).
You can use an alias in the SELECT statement to a more descriptive name:
SELECT COUNT(VoluneerID) NumVolunteers from ...
Depending on the underlying database engine, it is possible that the AS keyword migh be needed in front of the alias.
I have dealt very little with PHP, so I do not know about the 1 that is printed.
The number at the end should be the total number of rows returned. The best way I know of to remove it would be to put it in a hidden input, which means you can refer to it later with javascript or something if you really needed to, and also lets you hide it easily.. anything wrapped around the odbc_results_all function only effects the returning row count instead of the whole table (so you can use anything, maybe a div will be better).
echo "<input value=\"" . odbc_result_all($getVolID) . "\" type=\"text\" style=\"display:none;\">";

Resources