Dashboards & Visualizations

What is the proper JavaScript code to clear duplicate records in KVstore?

krishnarajapant
Path Finder

Hi,

I have followed the below link and created a kvstore to store the data from my dashboard app.

http://dev.splunk.com/view/SP-CAAAEZX

When I enter data to the input text boxes and click on submit, I can see the record is getting added. If I'm not entering any data to the input text boxes and click on submit, then it is taking the previous record values.

I believe this is because the previous value is not getting cleared from the record.

var record = { 
                "CustID": form_id, 
                "CustName": form_name, 
                "CustStreet": form_street,
                "CustCity": form_city,
                "CustState": form_state,
                "CustZip": form_zip 
            }; 

How do I clear this record after every click on Submit?

With Regards,
Krishna Rajapantula

1 Solution

krishnarajapant
Path Finder

Hi,

We are able to fix this by unsetting the token outside of .done function and adding alert with if clause.

if (form_id == null || form_name == null || form_street == null)
{
       alert("Enter all field values");
   return;
     }

"unsetToken("CustID")"
"unsetToken("CustName")"
"unsetToken("CustStreet")"

-Krishna Rajapantula

View solution in original post

0 Karma

krishnarajapant
Path Finder

Hi,

We are able to fix this by unsetting the token outside of .done function and adding alert with if clause.

if (form_id == null || form_name == null || form_street == null)
{
       alert("Enter all field values");
   return;
     }

"unsetToken("CustID")"
"unsetToken("CustName")"
"unsetToken("CustStreet")"

-Krishna Rajapantula

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Inside the done function for the service.request, just set the record to undefined:

.done(function(data) {  record = undefined; } )

You can also set it to an empty object {}, but either way it won't contain the data from the previous record.

0 Karma

krishnarajapant
Path Finder

Hi alacercogitatus,

Thanks for your response.

Yes, I have already tried by defining record= undefined and {} in the .done function for the service.request, still no luck.

I believe we have to empty the below in "record", as it is taking the input from browser.

            "CustID": form_id, 
            "CustName": form_name, 
            "CustStreet": form_street,
            "CustCity": form_city,
            "CustState": form_state,
            "CustZip": form_zip

-Krishna Rajapantula.

0 Karma

krishnarajapant
Path Finder

Hi Experts,

Any thoughts on the above query?

-Krishna Rajapantula

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...