indexOf in Catalog Client Script

stevenm
Kilo Guru

Does the indexOf in Catalog Client Script work?   This should be simple but it seems to fail at this code.   Neither side of the if statement executes and no other code after this executes.   I see no errors in the log.   What am I missing?   It's correctly grabbing the display_name off the alm_asset table but the indexOf.......argh!

  while (assettable.next())

  {

    thename = assettable.display_name;

    alert("in asset check " + thename);

    if (thename.indexOf("VMware") > -1 || thename.indexOf("VMWare") > -1 || thename.indexOf("Microsoft") > -1   )

    {

      countVirtual += 1;

    }

    else

    {

      countPhysial += 1;

    }

  }

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Stevem



Why not print thename.indexOf("VMware") and check what it is returning.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Deepak Ingale1
Mega Sage

Hey Steve



There are two things what I can see



1) Use of GlideRecord in client scirpt, its not at all encouraged due to SYNC nature of this call, better way is to use GlideAjax


2) you should use assettable.fieldName.getDisplayValue() method to get the display name of the field


stevenm
Kilo Guru

Oh my!   I've been staring at this so long and never saw my spelling error.   Great!   It's fixed, it works.


I have done this numerous time, typos !!!


Could you please go ahead and mark appropriate response as correct / helpful.