Run Clientscript one time only

Elias11
Giga Expert

Hi Experts

 

I am trying to create a client script that has to run only on time in every Record.

e.g. I have 2 fields, Field A and Field B , both are a reference type to the table users.

The Client script I have created is OnChange which if the Field A has changes or Loaded the Manager of the user of the field A will be set in the Field B.

 

So far so good. it works.,

 

Now as soon the manager in Field B is set for the first time I do not want anymore that the Field B changed.

the clientscript must not run till a new record is created.

 

Anyone an idea?

 

Thanks

Elias

1 ACCEPTED SOLUTION

Elias11
Giga Expert

I GOT IT



My Idea was correct but I wrote it wrong



I did ask if the value is Empty then run the script and if not return;



function onChange(control, oldValue, newValue, isLoading, isTemplate) {




var FieldB = g_form.getValue('u_fieldB');

if(FieldB== '') {
  var fieldA= g_form.getReference('u_fieldA');
  if (fieldA.manager != '')
  g_form.setValue('u_fieldB' , fieldA.manager);
} else {
  return;
}
}



Thank you


Elias


View solution in original post

8 REPLIES 8

yes and i would like to ask one more question. As per your scenario, the manager will differ for each person or based on the field A.



In this case, how you are going to solve the problem.



A has user Apple and manager as Steve


B has user Microsoft and manager as BillGate.



So you are like to say i choose Apple at first and set B value as Steve. After sometime i would like to change as Microsoft so Field B will point the Steve as manager ?


Yes the manager will differ for each users or team, depending on the user record manager field.



referencing to you example;



i would like to have if I choose in field A user Apple at first Steve will be his manager in the Field B and after I change Field A to User Microsoft the Field B should stay Steve and not changed automaticaly to BillGate-



Steve in the Field B should stay all the time in the form from the beginning till the end.



Elias


one more thing,



I had the idea to ask in my client script if the Field B is empty then run script else return.



but as my Field B is a user reference and it is not null it wont work.



Or what i am thinking was correct and I am doing something wrong?



Elias


Elias11
Giga Expert

I GOT IT



My Idea was correct but I wrote it wrong



I did ask if the value is Empty then run the script and if not return;



function onChange(control, oldValue, newValue, isLoading, isTemplate) {




var FieldB = g_form.getValue('u_fieldB');

if(FieldB== '') {
  var fieldA= g_form.getReference('u_fieldA');
  if (fieldA.manager != '')
  g_form.setValue('u_fieldB' , fieldA.manager);
} else {
  return;
}
}



Thank you


Elias