How can we use indexOf for system property?

Sathwik1
Tera Expert

Type field is a list collector....so it consists more than one value....so in that I need to check whether the below sysid is there or not...so I have used indexof method.....it is perfectly working fine....but hardcoding sys id  is not a best practice....so I want to replace with system property... is it possible to do without glideajax?

var grType = g_form.getValue('type');
var k = grType .toString().indexOf("d6263df300176cd7da6t54bf2632c");

1 ACCEPTED SOLUTION

For example I really quickly tested with below. Works instantly. The Client Scripts alerts a 0 (sysid found) or a -1 (no match).

System Property:

find_real_file.png

Display Business Rule:

find_real_file.png

onChange Client Script (for testing on Incident watch_list):

find_real_file.png

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

17 REPLIES 17

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Where are you using this? Platform UI, onLoad? Service Portal? onChange?

Do see g_form, so I suspect Client Side.

If for example Platform UI onLoad, you could use display business rule with scratchpad to get the contents of the system property. Then simply replace the hardcoded sys_id with the scratchpad in your client script.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

HI @Mark Roethof 

I am using onchange client script...I think in client script gs is not worked right?

So is it Platform UI or Service Portal?

If Platform UI, you can use the approach I mentioned using Business Rule which creates a scratchpad, which you can use in your Client Script.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

It's platform UI...

so as suggested used display business rule...used scratch pad...

but what is the format...I mean how to set in index of?

Display BR

  g_scratchpad.type= gs.getProperty("system_property_name");

client script

var k = grType .toString().indexOf("");

 

what needs to be write under index of? please help @Mark Roethof