hide choice in the list view

tushar_ghadage
Tera Contributor

Hi All , 

here I had requirement where i want to hide the close choice on the basis of new change request only 

for this I wrote display business rule and on load client script:

--------------------------------------------------------------------------

Display business rule:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var chg =new GlideRecord('change_request');
    chg.addQuery('sys_id',current.change_request);
    chg.query();

    if(chg.next())
    {
        g_scratchpad.changeState = chg.state;
    }

})(current, previous); 
-----------------------------------------------------------------
client script :
function onLoad() {
if ( g_scratchpad.changeState == '-5') {
g_form.removeOption('state', '3');
} else {
g_form.addOption('state', '3', 'Closed');
}
}

 --------------------------------------------------------------------------------------

but this does hide the choice closed choice in the list view of the change task. 

 

can anyone help ???

 

thankss !!

1 ACCEPTED SOLUTION

@tushar_ghadage 

I already informed you cannot remove the option from State field

You can just validate and stop user using the approach I shared earlier.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@tushar_ghadage 

on list only onCell edit client script runs and it cannot remove the choice. display business rule runs on form and not on list

you can simply validate and show message to user that you cannot change the choice

You can use before update business rule and stop the update using current.setAbortAction(true)

Cell edit client script like this

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

  var saveAndClose = true;
  if(newValue == '6' || newValue == '7' || newValue == '9'){
  alert('Not allowed');
  saveAndClose = false;
  } else {
  saveAndClose = true;
  }
callback(saveAndClose);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Okay will check

can you please help me on 

can we not hide the choice "closed" of change task in the list view using BR or oncelledit client script or any other method??

when change request is in new state.

@tushar_ghadage 

I already informed you cannot remove the option from State field

You can just validate and stop user using the approach I shared earlier.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader