I found a viable method, it may be somewhat inefficient but does work. Using “setInterval” in java script sets up a loop where I can call a function every X milliseconds. While this is not optimal it is functional. I would greatly prefer if we could natively select to retain or not retain values.
In this small javascript snippet I create a function to set my form values. This could set them to a default value or just assign an empty value as I do below. Then I set an interval timer to call this function every X milliseconds. In the snippet below I call it every 300000 milliseconds (5 minutes). In this manner a user who may be repeatedly deploying the fixlet with slightly varying values would have their entries retained for up to 5 minutes.
The 2 down sides to this are 1) it is always running and 2) It can catch a user in the middle of input. for example if it were open on their screen for 4:55 seconds when they start typing it will clear the form in 5 seconds forcing them to re-enter the values.
However I feel that in this particular use case, where retained form data could be negatively impact the targets, these down sides are acceptable.
I would LOVE to hear other ideas if they are out there ![:slight_smile: :slight_smile:](https://forum.bigfix.com/images/emoji/twitter/slight_smile.png?v=5)
function initForm() {
// Clear forms here
document.getElementById("division").value = "";
document.getElementById("application").value = "";
document.getElementById("environment").value = "";
document.getElementById("password").value = "";
}
setInterval(function(){ initForm()},300000);
Here is a larger example, shown in the exported .bes xml format:
<Fixlet>
<Title>FORM EXAMPLE</Title>
<Description><![CDATA[<BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr>
<script>
function initForm() {
// Clear forms here
document.getElementById("division").value = "";
document.getElementById("application").value = "";
document.getElementById("environment").value = "";
document.getElementById("password").value = "";
}
setTimeout(function(){ initForm()},1);
document.body.ontakeaction = function() {
var theDivision = document.getElementById( "division" ).value;
var theApplication = document.getElementById( "application" ).value;
var theEnvironment = document.getElementById( "environment" ).value;
var thePassword = document.getElementById( "password" ).value;
if (theDivision==null || theDivision=="")
{alert("Hey, you forgot to enter a Division! Please enter one on the Description tab before taking the action.");}
else if (theApplication==null || theApplication=="")
{alert("Hey, you forgot to enter an Application! Please enter one on the Description tab before taking the action.");}
else if (theEnvironment==null || theEnvironment=="")
{alert("Hey, you forgot to enter an Environment! Please enter one on the Description tab before taking the action.");}
else if (thePassword==null || thePassword=="")
{alert("Hey, you forgot to enter the password! Please enter one on the Password tab before taking the action.");}
else
{TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {}, { Division: theDivision, Application: theApplication, environment: theEnvironment, password: thePassword } );}
return false;
}
</script>
<table border=0>
<tr><td><LABEL for=division>Division:</LABEL></td><td> <INPUT id=division name=division value="default"> </td></tr>
<tr><td><LABEL for=application>Application:</LABEL></td><td> <INPUT id=application name=application > </td></tr>
<tr><td><LABEL for=environment>Environment:</LABEL></td><td> <INPUT id=environment name=environment > </td></tr>
<tr><td><LABEL for=password>Password:</LABEL></td><td> <INPUT id=password type=password name=password > </td></tr>
</table>
</P></BLOCKQUOTE>