How to increase count in OnChange client script

Sironi
Kilo Sage

Hi All,

after opening the Incident Record if user try to change category value from one value to another value without saving th record , for each change count has to increase.
Example : On INC Record Category : Network,  After Record Open,  

Without saving the value in record if user keeps changing Category software to hardware, hardware to another value...etc for each time changing the value  count has to increase.

after saving record , if we reopen the record again count has to come start from Zero.

i tried below script

 

Onchange :

var count=0;

 

if( newValue !=""){

if(count==0){

g_form.addInfoMessage("First change");

}else {

g_form.addInfoMessage("Not First change");

}

count++;

 

but here issue is for me it 's always coming "First Change" info message only.

 

 

6 REPLIES 6

hi @Simon Christens ,

code seems to be workng

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        NOW.count = 0;
        return;
    }
     g_form.addInfoMessage(NOW.count);
        if (NOW.count == 0) {
        g_form.clearValue('contact_type');
        g_form.clearValue('category');
    }

NOW.count++;
g_form.addInfoMessage(NOW.count);

}

 

above code seems to be working properly, not clearing value CATEGORY , CONTACT TYPE (which is working correct now ...! ).

My concern is : in future code should NOT work in OnLoad ,   Will it clear CATEGORY , CONTACT TYPE field values when record is loading ? Or after saving the record ? or once refresh the record ? 

because CATEGORY, CONTACT TYPE  field value should not be cleared at any moment in record is loading  Or after saving the record  Or  once refresh the record .

CATEGORY,  CONTACT TYPE  should  be clear only when we change value up and down, down to up in CATEGORY field. Not other time. 




Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Sironi ,

 

In the line 1 of your code, your setting the counter to 0. so when the value changes and when the onChange client script executes it again uses the same varable value count = 0, hence every time you change the category it will show as 1. 

 

To so attain your requirement you need to create a hidden field to store the counter number. No other go i guess...  I Hope this helps... 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect