Creating a counter Field

kartikey
Tera Contributor

Hi Everyone,

How do i create a Counter field and Ui Action, that starts with 0 and each time i click on a Custom UI action, it increments its value by 1, so if we click on the UI action 5 times, it increases its value by 5.

Thanks,
Kartikey

4 REPLIES 4

Community Alums
Not applicable

Hi @kartikey ,

 

I tried your problem on my PDI and I got the solution for that, currently I'm populating the value in short description you can change it to any field.

 

SarthakKashya2_0-1712664438696.png

 

var counter = 0;
alert("Outside Func");
function counterInc(){
	
	counter++;
	alert("Inside Func = " + counter);
	g_form.setValue('short_description', counter)
	g_form.update();
}

 

Please mark my answer helpful and correct if it helps you.

 

Thanks and Regards 

Sarthak

 

Hi @Community Alums 

it does not quiet work properly, because if i save a form at count 2, and then again click on UI action button i guess it is starting the count from beginning

Community Alums
Not applicable

Hi @kartikey ,

Yes I got the problem and now check this code it is working fine 

 

var c = g_form.getValue("u_counter");
function counterInc(){	
	c ++;
	alert("Inside Func = " + c);
	g_form.setValue('u_counter', c);
	g_form.update();
}

 

Please mark my answer helpful and correct if it helps you.

 

Thanks and Regards 

Sarthak

BrahmjeetTanwar
Tera Guru

Hey @kartikey ,

Create a field named "Counter" and put the default value as 0.

Then create UI Action and get the value of field var counter = g_form.getValue("counter");
counter++;

g_form.setValue("counter",counter);

g_form.update();

 

Please let me know if you have any questions.

Thanks,
Brahm