Can someone help me with CellEdit client script ...with an example ???

s_kumar
Mega Contributor

Can someone help me with CellEdit client script ...with an example ???

1 ACCEPTED SOLUTION

Hi Sandeep,


onCellEdit is a function that is used in the case of a list. If you want to write some script that should be executed on a list then you can do that by using onCellEdit function.



In my previous example:



It is checking in one field whether it is having the same old value or new value and if success then returns a success using the callback function.



Another small example for you:



The script below runs on the State field and prevents users from changing the State to closed in a list.   Hope this helps.



function onCellEdit(sysIDs, table, oldValues, newValue, callback) {


    var saveAndClose = true;



  if(newValue == 7){


  alert('Not allowed');


  saveAndClose = false;


  } else {


  saveAndClose = true;


  }



callback(saveAndClose);


}


View solution in original post

16 REPLIES 16

but in your example you have taken value 7 ...why that ..is it something like we have some value for one value in list ....



and this preventing user to enter specific value ...can achieve with onChange Scripts also then why only cellEdit.



One   more doubt i have in this ......


will it work in case of list only or we can have this on text box also ..


like


if i want run celledit script ..when i am running this client script ..it should check whether i am entering correct value or not ..



Thank you



Sandeep Kumar


I will explain.


Go to some incident and right click state field and select configure dictionary.Then you can see the choice values for the field as choices .If you look at that you can see 2 fields for each choice ,One as value and other as label.


Label is the value that will be displayed to the user whereas value will used in our scripts. So here I have used the value for the option closed.(here Value is 7 and label is closed). Hope this makes it clear for you.


Hi Ajai,


I have done same as you have asked ...but still its not working ..i am sending you details what i did .


This is the table i have created ..



Choice Field label and value both are same in my case .


table.PNG


and the cellEdit client script is below...which run on cellEdit of cell field of table.



function onCellEdit(sysIDs, table, oldValues, newValue, callback) {


      var saveAndClose = true;


      if(newValue == "test2")


              {


              alert("Not allowed");


              saveAndClose = false;


      }


      else


              {


              saveAndClose = true;


      }


      callback(saveAndClose);


     


}



Can you please help me in this ..?



Thanks


Sandeep Kumar


I just tried the same script and got the output correctly.See the screenshot below:


find_real_file.png


Actually are you trying for list edit or edit the field on the form.


If you want to have some modifications done when a field value changes then you have to use onchange not oncelledit


yeah Ajai its working ..


but here i have one doubt..



when i am choosing value first time from UI its allowing me but when i am changing value after inserting value in table its not allowing me ..


why it is like that?



is it like when we want to stop end user from inserting specific value ..we have to use on change script.