Client script (cell edit) in List not working - ServiceNow Community

Client script (cell edit) in List not working

suryan
Kilo Expert

Below is Client script wrote for type: on cell edit.

If old value is not 27(Delivered to client) and change to new state 27 then it should allow only if manager review met is 'Yes'. For testing purpose i add alerts after

  if (oldValue !=27),     if (newValue==27) and before var managerreview, script is not running after   if (newValue==27). I checked the field name it is correct. This is not working on list view.

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

{

      var saveAndClose =false;

        for (var i = 0; i < oldValues.length; i++)

        {

                  var oldValue = oldValues[i];

        if (oldValue !=27)

        {    

                  if (newValue==27)

                  {

                            var managerreview = g_form.getDisplayValue('u_manager_review_met');

                            if (managerreview=='Yes')

                            {

                                      saveAndClose = true;

                            }

                  }

        }

}

        if(saveAndClose == false)

                  {

                            alert("This State change is Not Allowed.");

                  }

//Type appropriate comment here, and begin script below

callback(saveAndClose);

}

Thanks in   advance..

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Surya,



g_form.getDisplayValue will not work at client side. You need to create a BEFORE business rule and then abort the form updates per your logic.


Reference:


http://wiki.servicenow.com/index.php?title=Scripting_in_Business_Rules#Aborting_a_Database_Action_in...


changed getDisplayValue to getvalue, this is clientscript written for list edit.


As Pradeep suggested none of the g_form operations can be accessible from list view because it works only after loading of a form. From oncelledit you can access a field which you have selected on the script through newValue and oldValues. Rather you should use business rule to abort updation with an info message.



Regards,


Souren


so how to check this condition in client script for list edit.