Is substring() method available in the String object in non global scope?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 02:19 AM
I am using below code in some non global application scope
current.floor = parseInt(current.room.substring(0,1)); // where 'room' is string type and 'floor' is integer type.
but it is not working, i am getting error
but when i am using
current.floor = parseInt(current.room.toString().substring(0,1));
it is working perfectly fine.
Why do i need to use toString() for a string type variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 04:04 AM
Hi Swarnadeep,
current is reference of GlideRecord. so it is a object. so when u do current.anyfield it returns propertiy of object..
see below image.
short descripton has type string but it will return Object. see below
so u must use toString() method to convert it to proper String.
I hope it helps.
mark correct/helpful/like based on impact.
Regards,
Rushit Patel

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 05:06 AM
Hi Rushit,
Try running the below code
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0000055');//take any incident number for any particular
gr.query();
while(gr.next()) {
gs.log(typeof gr.short_description);
}
this will also return "object".
var a = new String('abc');
gs.log(typeof a); // it will return object.
While,
var a = 'abc';
gs.log(typeof a);//it will return string, because it is primitive.
This is because short_description might not be a primitive string. Its an object of wrapper class String() and String() class has a toString() method overriden to that of Object class. And moreover String() class also has substring() method.
So my question is why it is not using that method, it might be because of application scope issue. Restricted access in non global application scope might be the issue.
Thanks & Regards,
Swarnadeep Nandy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 05:26 AM
I checked in global application scope and it is working. I mean the substring() method for short description.
gs.addInfoMessage(current.short_description.substring(0,10));// It will return the first 10 letters from the short description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2015 05:29 AM
Yeah man..i checked it too. this is super wierd. there are lots of wierd thing about scoped API,im not surprised.!