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

vignesh parthib
Tera Guru

Hi @ack 

 

Can you try below script,  

var regEx new RegExp('(?<="environmentName" : ).*''j'); - is not supported in all JavaScript engines
 
var UrgencyPriority;
var incDesc = fd_data.subflow_inputs.ah_alertgr.additional_info;

try {
    var parsedDesc = JSON.parse(incDesc);
    var envName = parsedDesc.environmentName.toUpperCase();

    if (envName === "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;
        }
    }
} catch (e) {
    // Handle parsing error or missing environmentName
    UrgencyPriority = '3'; // Default fallback
}

return UrgencyPriority;

 

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."