How to add property in IF Condition?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:48 AM
Hello,
You can simply use the below syntax
var varName= gs.getProperty('PropertyName ');
if(PropertyName == 'true'){
//code
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:51 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 06:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 08:14 PM
Hi,
but you are comparing property with true value
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader