count how many times a button is clicked from portal

Sanchita02
Tera Contributor

Hi ALL,

 

I have a requirement that I have a button on my portal when we click on button there is a popup asking to fill some ID. When we fill the ID if check from the table if the ID i have filled is correct or not. If it is wrong it shows the error message Till here i have developed. I need help for my further requirement which is if the used is typing wrong ID more than three time a task should be generated. So, How can we track the number of times the user has given the wrong ID. Please help me with the code 

1 ACCEPTED SOLUTION

1) you can declare one count variable on top i.e c.count=0;

2)  In else part of code just do

  c.count++; // and after this compare with number you would like to have

  if(c.count == 3)

{

var gr = new GlideRecord("CTASK");

gr.initialize();

gr.some_field="working"; // you can use here your field to pre populate some value if needed.

var sysID = gr.insert(); // It will return sysId of task created;;

console.log(sysID+" sysId of record");

}

 

please mark this correct if it is helpful!

View solution in original post

8 REPLIES 8

Hi @Ankur Bawiskar 

 

We have a portal where we have created a table which is populating the data from slm_hardware table. Data populated is actually the devices which are assigned to you. So on click of this verify table we have a popup which ask for verification ID.  when verification id is wrongly entered it displays error message. So, it he enters wrong ID more than 3 times we need to create a CTASK.

This is not a catalog we have created a table.

 

Regards

Sanchita

Can you please share onclick function which is in client script of widget i.e c.pop

Hello @Nikhil Soni 007 

 

Client controller

 

c.submitVerification = function(asset_tag, sys_id) {
        var enteredTag = asset_tag;
        var enteredText = document.getElementById('verificationText_' + sys_id).value;
        if (enteredTag == enteredText) {
            // Trigger the "open" action
            //c.user(asset_tag, 'open');
            c.data.currentverified = sys_id;
            c.server.update().then(function() {
                c.data.currentverified = "";
            });
        } else {
       
                alert("Verification Failed please enter correct asset tag- " + asset_tag);
           
        }
    }

1) you can declare one count variable on top i.e c.count=0;

2)  In else part of code just do

  c.count++; // and after this compare with number you would like to have

  if(c.count == 3)

{

var gr = new GlideRecord("CTASK");

gr.initialize();

gr.some_field="working"; // you can use here your field to pre populate some value if needed.

var sysID = gr.insert(); // It will return sysId of task created;;

console.log(sysID+" sysId of record");

}

 

please mark this correct if it is helpful!