How to check in a client-script is a field value = "--None--"

Wim2
Kilo Expert

Hi

If a new Linux or Windows Server is added, they have default values for the field

  • Status = Installed
  • Operational Status = Non-Operational

For users with the Role "ecmdb_admin" I wouldlike to change this in:

  • Status = On Order
  • Operational Status = Order

I did create a client script, but the check if the field "Status" is not filed does not work. In other words, every Windows or Linux Server that is opend is changed to the new defined values.

I did try 

  • if (g_form.getValue('install_status','')) {
  • if (g_form.getValue('install_status','--None--')) {

This is the script:

function onLoad() {
    //alert("Status will be set to On Order.");
    if (g_form.getValue('install_status', ''))
      {
      if (g_user.hasRoleExactly('ecmdb_admin'))
      {
        g_form.setValue('install_status', 2);
        g_form.setValue('operational_status', 10);
      }
    }
  }

 

1 ACCEPTED SOLUTION

Hi,

something like this

if(g_form.isNewRecord()){

        g_form.setValue('install_status', 2);
        g_form.setValue('operational_status', 10);

}

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you are using OOB None option then it's value is empty string

you can use that to compare

updated script below

function onLoad() {

    if (g_form.getValue('install_status') == '')
      {
      if (g_user.hasRoleExactly('ecmdb_admin'))
      {
        g_form.setValue('install_status', 2);
        g_form.setValue('operational_status', 10);
      }
    }
  }

Regards
Ankur

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

Hi Ankur

In fact this is a correct answer.

unfortunately, I made a mistake. If I create a new Windows or Linux Server the "Status = Installed". I cannot check this value for this is a quite normal status. The default values should only be for new created Windwos or Linux Servers. So the question would be:
How can I check if it concenrs a new created record. So

If "New Record" {

        g_form.setValue('install_status', 2);
        g_form.setValue('operational_status', 10);
      }

 

Can you help me with this?

 

Greets

Wim

Hi,

something like this

if(g_form.isNewRecord()){

        g_form.setValue('install_status', 2);
        g_form.setValue('operational_status', 10);

}

Regards
Ankur

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

Thank You Ankur

This is working great.

With a test on a role (hasRoleExactly) I was able to implement it for a specific group of users.

Greets

Wim