Script Understanding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 02:28 PM - edited 05-09-2024 02:54 PM
Can I get some exercise to work on scripting from the basics , To be successful in development...
Thank You!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 02:51 PM
The Index of is useful to search a substring within a string. and -1 in this context indicates that the substring "NEW" was not found in the subject of the email.
Thanks and Regards
Sai Venkatesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 02:52 PM
email.subject.indexOf('NEW')!=-1 is like saying NEW existed in the subject. Index of return the location where it found the word in this case in the string. When you see ==-1 then that means the word was not found in the string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 02:55 PM
Hi Hitesh,
Breaking it down by each condition:
Condition 1 (email.from == 'exampe1@gmail.com'): Checks if the sender of the email is 'exampe1@gmail.com'.
Condition 2 (email.subject.indexOf('NEW') != -1): Checks if the subject of the email contains the substring 'NEW'.
Condition 3 (email.subject.indexOf('UPDATE') == -1): Checks if the subject of the email does not contain the substring 'UPDATE'.
Condition 4 (email.subject.indexOf('RESOLVED') == -1): Checks if the subject of the email does not contain the substring 'RESOLVED'.
Condition 5 (email.from != 'example1@gmail.com'): Checks if the sender of the email is not 'example1@gmail.com'.
Now to explain some of the methods used within the conditions:
The indexOf() method is used to find the position of a substring within a string. If the substring is not found, it returns -1. So, indexOf('NEW') != -1 checks if the string 'NEW' is present in the subject of the email.
The logical operators && (logical AND) and || (logical OR) are used to combine these conditions.
In summary, this code is checking certain conditions related to the sender's email address and the subject of the email, and will then trigger the notification accordingly.
Also, there seems to be a typo in the code where 'exampe1@gmail.com' is spelled incorrectly and different to that of condition 5.
Hope that helps.
Regards,
Wind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 02:58 PM
There is a course in now learning "Scripting in servicenow" and it will be very helpful and below is the Link
Thanks and Regards
Sai Venkatesh