DesiLogi Posted September 20, 2016 Report Share Posted September 20, 2016 I need to reference a calculated field's value for use in an If/Then function in js. The calculated field uses a SELECT to calculate a View's total records, which is either null or with some records in the result. If the calculated field has a null value I need something to happen vs if it's not null. Here's the code: <script> var v_itemsid = parseFloat(document.getElementById("EditRecordcalcfield18").value); if(!isNaN(v_itemsid)) { document.getElementById('section1').style.display = "block"; document.getElementById('section2').style.display = "none"; } else { document.getElementById('section1').style.display = "none"; document.getElementById('section2').style.display = "block"; } </script> I've used this code before with a regular table field: how is the calculated field referenced where EditRecord is (EditRecordcalcfield18 obviously isn't right)? I don't know the syntax. Any help would be great- thanks in advance. Quote Link to comment Share on other sites More sharing options...
DesiLogi Posted September 20, 2016 Author Report Share Posted September 20, 2016 No need to answer this. If anyone needs something similar, I did a workaround by using a virtual field that On Load brings in the calculated field's value. Then I used the Virtual field as the reference in the js. Quote Link to comment Share on other sites More sharing options...
gregcoiro Posted March 26, 2018 Report Share Posted March 26, 2018 Hi, Can I ask how you accomplished this as I have been having difficulty trying to figure out how to reference a calculated field in js. I need to essentially take the calculated field’s value and copy it into a text field on the same page? Appreciate any help. Quote Link to comment Share on other sites More sharing options...
DesiLogi Posted March 26, 2018 Author Report Share Posted March 26, 2018 Hi Greg, To do this use a Virtual field to get the calculated field's value. Set the Virtual field to Hidden and use the Default Value to get the calculated field's value. Then in the footer use this script: <script> var v_virta = document.getElementById("cbParamVirtualField").value; if(v_virta=="whatevervalue") { document.getElementById('section1').style.display = "block"; } else { document.getElementById('section1').style.display = "none"; } </script> The "v_virta" is getting the value of the virtual field and making it a variable so the js can use it. The 'if' section uses the variable (that comes from the virtual field, that itself comes from the calculated field) to decide what to do based on the value. Quote Link to comment Share on other sites More sharing options...
gregcoiro Posted March 26, 2018 Report Share Posted March 26, 2018 Hi DesiLogi, Thank you! This worked perfect as I just could not figure this out over the weekend. Thank you for the detailed explanation and providing this great solution. Appreciate your assistance and quick reply. Quote Link to comment Share on other sites More sharing options...
sgriesbach Posted November 25, 2018 Report Share Posted November 25, 2018 If I understand this correctly, I cannot reliably use Formula fields in a script at the end of a form. Indeed, it does not seem to work for my case, so I tried what you describe here and I still can't get it to work. My form is a Report form with a Details page. I have several Formula Fields set up in a table. Once the user submits the form, the Formula Fields get recalculated and are in the table nicely. The form has Ajax loading enabled, and the wizard is set to "Display Search Form Above the Results". In the JS at the end of this form, I want to sum up several of the Formula Fields, store the sum and do some other operations with the sum. I've tried setting up Virtual fields for each of the Formula fields, but I do not seem to get the Virtual values into the script. Example Details Page Setup: Formula field called ADJ set to Display Only and do not pass field value as a parameter [@ADJ] (note: I did try passing it directly, that doesn't work either) Virtual field called Virtual1 set to Hidden, set to receive value of ADJ on load, and pass field value as a parameter [@Virtual1] Here's a stub of the footer JS <script type="text/javascript"> document.addEventListener('BeforeFormSubmit', function(event) { var v1 = document.getElementById("EditRecordVirtual1").value; do some math with v1... // end of function }); </script> I'm not getting the v1 value, the script stops/fails at that line. Thanks for any advice! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.