Jump to content
  • 0

Using Rules & Criteria To Selectively Display Certain Fields


maverick

Question

I have a Search and Report Datapage in which I need to selectively display certain fields.

 

More specifically, each record has a fuel_type field. If this fuel_type is set to Oil, I need to display the associated Oil Price in the report. If fuel type is set to Natural Gas I need to display Natural Gas Price and if fuel_type is Kerosene, I need to display Kerosene Price.

          e.g. if (fuel_type == Oil)

                 {

                     show Oil_price;

                 }

                else if (fuel_type == Natural Gas)

                {

                    show Natural_gas_price;

                }

                else 

                {

                    show Kerosene_price;

                 }

 

I think there is a way to do this with Rules & Criteria. Can someone please guide me? Thanks in advance.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

You can try to add a calculated field using this formula:

CASE
WHEN [@field:fuel_type] = 'Oil' THEN document.write([@field:Oil_price]);
WHEN [@field:fuel_type] = 'Natural Gas' THEN document.write([@field:Natural_gas_price]);
ELSE document.write([@field:Kerosene_price]);
END

Select field names from picker to make sure they are in correct format. Let me know if that works for you

Link to comment
Share on other sites

  • 0

Thanks Maymusic! Once again you came thru with your guidance and timely help. I really appreciate it!

 

However I did find another way to do this using Rules and Criteria as suggested here 

http://howto.caspio.com/datapages/forms/conditional-forms/

 

Essentially, I put "oil_price", "natural_gas price" & "Kerosene_price" in different Sections.

 

Then I setup the following rules

              if (fuel_type != Oil)

              {

                    hide Section associated with Oil_price

              }

              if (fuel_type != Natural_gas)

              {

                    hide Section associated with Natural_gas price

              }

              if (fuel_type != Kersosene)

             {

                    hide Section associated with Kerosene price

             }

Since fuel_type can only be set to 1 value at any time, this seems to work really well.

 

I appreciate your input. thanks again MayMusic!

 

Mav

Link to comment
Share on other sites

  • 0

I would like to thank Maverick for providing his code and MayMusic for contributing to this thread, it was a major "Ahh Ha" moment for me (@ 4am on a sunday morning).
I was having troubles with rules when I found this post. With myself in the early stages of developing a "programmers mindset" I would look at conditional rules as one sided. Example.. if virt1 (contains) "show" then hide virt2 virt3 virt4, then when I went to write the next rule to show virt2 and hide 1,3,4 all the virt fields were used and I could not continue.
Now with Mavericks coding example I understand to look at conditional logic in both directions and take the path of least resistance. Example.. if virt1 (does not contain) "show" hide virt1, then same rule conditions for 2,3,4. Same result with just one step by declaring (does not contain) as opposed to 4 steps declaring (contains).

It may not seem important to show your code in a thread, but I can tell you it is much appreciated when it is available to learn from.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...