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-29-2022 01:39 AM
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
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-29-2022 02:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:49 AM
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
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-29-2022 05:00 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 06:37 AM
Hi,
which field holds metric type sysId?
use that in condition in place of metricField
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader