The CreatorCon Call for Content is officially open! Get started here.

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

Dharmesh1
Kilo Contributor

Hello,

 

You can simply use the below syntax

var varName= gs.getProperty('PropertyName ');

if(PropertyName == 'true'){

 

//code

 

}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

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').toString() != "true"){
	current.setValue('state', 'canceled');
} else {
	current.setAbortAction(true);
}

Regards
Ankur

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

Hi Ankur,

I have tried the above code and not working. I'm storing 4 metric type sys ID's in the value field of the property which is mentioned in the If condition "property_name1".

Business Rule Condition

state changes to Cancelled

Condition 1

Actually My requirement is the state should not change to cancel for the metric type which is mentioned in the property_name1 if the condition duration.getDayPart() > days is true also.(abort action)

Condition 2

If Metric Type is other than this 4 metric type which is mentioned in the property (property_name1) and duration.getDayPart() > days is true then state should change to cancel.

Condition 3

If Metric Type is other than this 4 metric type which is mentioned in the property (property_name1) and duration.getDayPart() > days is false then state should not change to cancel(abort action)

Please suggest

Regards,

Sruthi

Hi,

but you are comparing property with true value

Regards
Ankur

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