Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

indexOf comparison evaluates to true

Posted on 2014-02-07
4
Medium Priority
?
276 Views
Last Modified: 2014-02-07
Hello Expert,

Working with an application called ServiceNow. It has a function
called Email Inbound Action.  The Email Inbound Action has a single
line text box into which a JavaScript statement can be written.
If the statement evaluates True an incident is created.
If the statement does not evaluate True an incident is not created.

ServiceNow is getting an email from another appl called SolarWinds.
The servers in SolarWinds are marked PRODUCTION Y or
PRODUCTION N and send an email to ServiceNow with the PRODUCTION
attribute if the server goes down.

If PRODUCTION attribute in SolarWinds set to Y: in email body: "PRODUCTION_Y/N:Y":  create incident.
If PRODUCTION attribute in SolarWinds set to N: in email body: "PRODUCTION_Y/N:N":  do not create incident.
If PRODUCTION attribute in SolarWinds not set (null): in email body: "PRODUCTION_Y/N:":  do not create incident.

I have got it to work for the first two cases with the condition
email.body_text.indexOf("PRODUCTION_Y/N:N") == -1

The fly in the ointment is if the PRODUCTION attribute is not set I get the
third case: "PRODUCTION_Y/N:":

If "PRODUCTION_Y/N:" ) comes in the email body the incident is created
which is incorrect.

Tried Condition:
(email.body_text.indexOf("PRODUCTION_Y/N:N") == -1 || email.body_text.indexOf("PRODUCTION_Y/N:  ") == -1)
but this does not stop the unset attribute. I think because  the second half of the OR statement is looking for a blank string when what is being returned is no text beyond the semicolon.

There are lots of ways using MATCH() or TEST() or REGEX() to check for strings but I
need to return a boolean false if a part of a string does not exist.

Any ideas?

Thanks

Allen in Dallas
0
Comment
Question by:Allen Pitts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 2000 total points
ID: 39843052
Don't test for the null.  
NULL and N call for the same action. Therefore the logic is if not Y do not create else create.
Cd&
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39843257
I need to return a boolean false if a part of a string does not exist.

var create_incident = email.body_text.indexOf( "PRODUCTION_Y/N:Y" ) >= 0;

Open in new window

or :
var dont_create_incident = !email.body_text.indexOf( "PRODUCTION_Y/N:Y" ) >= 0;

Open in new window

or :
var create_incident = email.body_text.indexOf( "PRODUCTION_Y/N:Y" ) >= 0;
var dont_create_incident = !create_incident;

Open in new window

0
 

Author Closing Comment

by:Allen Pitts
ID: 39843385
Hello COBOL,

That worked. Code string
email.body_text.indexOf("PRODUCTION_Y/N:N") != -1
Says if indexOf("...Y/N:Y") is not false create an incident.

Thanks

Allen in Dallas
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 39843389
if (email.body_text.indexOf("PRODUCTION_Y/N:Y") > -1) {
	// create incident
} else {
	// don't create incident
}

Open in new window

or more simply
if (email.body_text.indexOf("PRODUCTION_Y/N:Y") > -1) {
	// create incident
}

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question