Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

script always looping to else loop

ack
Tera Contributor

Hello Folks,

 

I have written below code to set impact on incident based PRO/Non Prod value. but it always going to else loop. Please let me know what will error in below code.

 

var UrgencyPriority;
var incDesc = fd_data.subflow_inputs.ah_alertgr.additional_info;
//var incDesc = fd_data.trigger.current.additional_info;
var regEx = new RegExp('(?<="environmentName" : ).*', 'j');
var matchData = regEx.exec(incDesc);
var matchDateUp = matchData.toString().toUpperCase();


if(matchDateUp == "NON PROD") {
UrgencyPriority='2';

}

else{

var evntType = fd_data._6__look_up_record.error_message;

if (evntType == "No Record Found") {
UrgencyPriority='3';
}
else
{
UrgencyPriority = fd_data._5__calculate_values_based_on_the_alert.incidenturgency;
}}

return UrgencyPriority;

 

Thanks in advance.

 

5 REPLIES 5

SanjivMeher
Mega Patron
Mega Patron

I think the reason is obvious. Your variable matchDateUp is not setting to NON PROD.

Can you add a gs.info to check what is the value you have in that variable matchDateUp and in incDesc?

 

Could be an issue in below two lines

var regEx = new RegExp('(?<="environmentName" : ).*', 'j');
var matchData = regEx.exec(incDesc);


Please mark this response as correct or helpful if it assisted you with your question.

ack
Tera Contributor

Hi @SanjivMeher ,

 

Thank you for the quick response.

 

value are coming correctly.

 

matchDateUp::"NON PROD",

matchDate::"Non Prod",

incDesc  = getting entire description (not pasting here).

 

value are getting each line as expected but always going to else loop.

Can you do if (matchDateUp.indexOf("NON PROD")>-1) instead, incase there are unwanted space?


Please mark this response as correct or helpful if it assisted you with your question.

DGAJ
Giga Guru

Hi @ack ,

You can replace if(matchDateUp == "NON PROD") with if(matchDateUp.replace(/["']/g, "").trim() == "NON PROD")

 

*******************************************************************************************
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards,

DGAJ