How to restrict "insert and stay" button to add duplicate record in Hardware table.

Hrishabh Kumar
Giga Guru

We have an option of "insert and stay" in the form context menu, which creates a same record as current record.

I want to stop this feature on Hardware table (alm_hardware) .

When we click on the "insert and stay" on the hardware form, it creates a duplicate record in the hardware table with same asset_tag and serial_number, which is something we don't want. How can I restrict the "insert and stay" feature on Hardware Table. (alm_hardware).

 

insertandstay.PNG

 

I have written a BR on Hardware table (alm_hardware) to avoid entries with duplicate asset_tag and serial_number and it working on manual creation of assets in the table, but not with "insert and stay" option.

 

 

1 ACCEPTED SOLUTION

Hrishabh Kumar
Giga Guru

I achieved this by adding simple condition in "insert and stay" UI's condition.

1) open the "insert and stay" UI action.

2) add this to the condition:  (current.getTableName() != 'alm_hardware')

   What this does is it hides the insert and stay option from the context menu when we are in "alm_hardware" tables  form view.

  We can easily achieve this requirement for any other table also by adding the table name in place of "alm_hardware". ie.. (current.getTableName() != '<any_table_name>').

View solution in original post

8 REPLIES 8

Manmohan K
Tera Sage

Hi @Hrishabh Kumar 

 

You need to create a UI action with the same 'action name' as global Insert and stay button but give different condition so it doesn't show on alm_hardware table

 

Example: add to the conditions field current.getTableName() !='alm_hardware'

 

This creates a UI action override and will no more show Insert and stay button in hardware table

 

Hrishabh Kumar
Giga Guru

I achieved this by adding simple condition in "insert and stay" UI's condition.

1) open the "insert and stay" UI action.

2) add this to the condition:  (current.getTableName() != 'alm_hardware')

   What this does is it hides the insert and stay option from the context menu when we are in "alm_hardware" tables  form view.

  We can easily achieve this requirement for any other table also by adding the table name in place of "alm_hardware". ie.. (current.getTableName() != '<any_table_name>').

Manmohan K
Tera Sage

For future readers of the thread - 

 

Modifying the existing OOB insert and stay button is not a good practice as you will stop receiving updates from ServiceNow for that UI action during upgrades

 

 The better way of doing it is by creating a UI action with the same 'action name' as global Insert and stay button but give different condition so it doesn't show on alm_hardware table.

 

Example: add to the conditions field current.getTableName() !='alm_hardware'

 

This creates a UI action override and will no more show Insert and stay button in hardware table 

 

 

Thanks for the important information.👍

It was helpful.

@Manmohan K