In the list view, i want to clear the Assigned to field if the Assignment group changes

GP001
Tera Contributor

Hi All,

 

In the list view, i want to clear the Assigned to field if the Assignment group changes. Can anyone please correct my below code :

onCellEdit :

 

 if(newvalue)
   { 
 g_form.setValue('assigned_to','');
   saveAndClose = true;                     //It doesn't work. 
   } else {
    saveAndClose = false;
   }
 
Thank you.!
1 ACCEPTED SOLUTION

SAI VENKATESH
Tera Sage
Tera Sage

Hi @GP001 

 

g_form is not available in list view scripts. It is only available in form view scripts.

 

and can you try the below script :

 

1 way of doing it.

 

 

 

function onCellEdit(sysIDs, table, oldValue, newValue, callback) {
    var saveAndClose = true;

    if (newValue != oldValue) {
        saveAndClose = true;
        var gr = new GlideRecord('incident');
        if (gr.get(sysIDs)) {
            gr.setValue('assigned_to', '');
            gr.update();
        }
    } else {
        saveAndClose = false;
    }
    callback(saveAndClose);
}

 

 

 

Here, Glide Record is not a good practice to use in client script. please enhance this by creating a script include or use business rules

 

and another way business rules(highly recommend)

you need to use before update business rule; 

 

when condition : assignment group changes 

action : assigned to Empty

then save 

 

 

It will work and is working as expected in my PDI.

Thanks and Regards

Sai Venkatesh

View solution in original post

2 REPLIES 2

SAI VENKATESH
Tera Sage
Tera Sage

Hi @GP001 

 

g_form is not available in list view scripts. It is only available in form view scripts.

 

and can you try the below script :

 

1 way of doing it.

 

 

 

function onCellEdit(sysIDs, table, oldValue, newValue, callback) {
    var saveAndClose = true;

    if (newValue != oldValue) {
        saveAndClose = true;
        var gr = new GlideRecord('incident');
        if (gr.get(sysIDs)) {
            gr.setValue('assigned_to', '');
            gr.update();
        }
    } else {
        saveAndClose = false;
    }
    callback(saveAndClose);
}

 

 

 

Here, Glide Record is not a good practice to use in client script. please enhance this by creating a script include or use business rules

 

and another way business rules(highly recommend)

you need to use before update business rule; 

 

when condition : assignment group changes 

action : assigned to Empty

then save 

 

 

It will work and is working as expected in my PDI.

Thanks and Regards

Sai Venkatesh

Hi @SAI VENKATESH,

Oh yes, it slipped my mind that we can't use g_form in list view. Thanks a lot for the suggestion. Your code works perfectly; i just needed to change ' if(newValue) '.

 

I much appreciate your help.