How to add property in IF Condition?

sruthig
Tera Expert

How to add property in IF Condition?

I have tried below and not working.

var days = gs.getProperty('Property_name');

var today = new GlideDate();

today = today.getByFormat("MM-dd-yyyy");
var due_date = current.due_date;
var duration = GlideDateTime.subtract(new GlideDateTime(due_date), new GlideDateTime(today));

if (duration.getDayPart() > days && (gs.getProperty('propert_name1) != 'true')){
current.setValue('state', 'canceled');
} else {
current.setAbortAction(true);
}

Please let me know syntax which i used is correct or not?

Regards,

Sruthi

 

16 REPLIES 16

Hi,

that property holds 4 sysIds

then why are you comparing it with true?

is there any field on your table which holds metric sysId and you want to check if the metric sysId is one of that 4?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Okay Ankur. How to check if the metric sysId is one of that 4 in the IF Condition. 

 

if (duration.getDayPart() > days && gs.getProperty('propert_name1')){

current.setAbortAction(true);

}

else if(duration.getDayPart() < days && gs.getProperty('propert_name1')){

current.setAbortAction(true);

}

else {

current.setValue('state', 'canceled');

}

 

I have to add one more condition here like if duration.getDayPart() < days and metric type is not any of this 4 then state should not change to cancel. 

if duration.getDayPart() > days and metric type is not any of this 4 then state changes to cancel. 

Please suggest.

Regards,

Sruthi

 

Hi,

to check if metric sysId is one of those 4 do this

gs.getProperty('property_name').indexOf(current.metricField) > -1

to check if metric sysId is not one of those 4 do this

gs.getProperty('property_name').indexOf(current.metricField) == -1

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

What is meant by (current.metricField)>-1 and current.metricField) == -1.

I have given the condition all the condition the state got cancelled.

Regards,

sruthi

Hi,

which field holds metric type sysId?

use that in condition in place of metricField

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader