Using a client script to edit one column in a List view after editing another

johnsgp
Mega Expert

I have a list view and would like to change one column after editing another.   For example, in an incidents view, I might want to clear the User when the User Group changes to ensure the person editing the list assigns a new user to the incident.   I have already done this in a form using g_form.setValue('column_name', '') in the onChange function, but in a list I would need to pick the selected row, I'm guessing using the table variable in the onCellEdit function?   I imagine I can write script includes or business rules but this feels like it should be quite straightforward to do.

This does not work (perhaps I'm using the wrong column_name?):

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

  g_form.setValue('column_name', '');

  callback(true);

}

1 ACCEPTED SOLUTION

johnsgp
Mega Expert

I don't think this question is likely to get a reply that directly answers the question because the documentation is not clear on the matter and it is becoming stale now.   The replies so far have either indicated alternative solutions or have hinted that it might not be possible without being definitive.   I have myself found an alternative solution to my problem but the question remains unanswered.   I will try to close it now.


View solution in original post

7 REPLIES 7

tkalpa005
Tera Expert

Hi,


onChange() works only in form view, It will not work in List View, Best option you have is write a business rule and there you can check the value.



Thanks


KB


Thanks KB.   I only tried onChange on the form.   My question was about using onCellEdit on the list.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Johns,



I don't think using cellEdit you can set the value of other field.


Hi Pradeep



Do you have a reference for saying this?   I'm clarifying because you wrote "I don't think that" which sounds like you're not sure.



I would guess that it must be possible.   It seems to me that there must be an object on the client side otherwise the browser could not display the list.   So it seems entirely possible to do this with Javascript if only I knew which object I can refer to, and if that object is accessible.   However, if it is documented as impossible, I will try another approach like business rules. The disadvantage of business rules is that they only run on save/update so the user gets feedback quite late.



John