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 10:49 PM
iHi Ankur,
if (duration.getDayPart() > days && gs.getProperty('propert_name1').toString() != "true"){
current.setValue('state', 'canceled');
} else {
current.setAbortAction(true);
}
conditions
1) If duration.getDayPart() > 365 and gs.getProperty('propert_name1').toString() != "true")
then current.setAbortAction(true); - state should change to cancel
2) If duration.getDayPart() < 365 and gs.getProperty('propert_name1').toString() != "true")
then state should not change to cancel.
3) If duration.getDayPart() > 365 and gs.getProperty('propert_name1').toString() == "true")
then state should not change to cancel.
4) If duration.getDayPart() < 365 and gs.getProperty('propert_name1').toString() == "true")
then state should not change to cancel.
How can I add this condition in the business rule?
Please suggest
Regards,
Sruthi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 11:22 PM
Hi,
you already gave all the if conditions in your response
what's not working or which use case is not working?
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 11:31 PM
Hi Ankur,
As per the condition which is given in the business rule state should not changes to cancel right?
condition
If duration.getDayPart() > 365 and gs.getProperty('propert_name1').toString() != "true")
then state should not change to cancel.
But the below scenario state changes to cancel.
if (duration.getDayPart() > days && gs.getProperty('propert_name1').toString() != "true"){
current.setValue('state', 'canceled');
} else {
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 12:44 AM
Hi,
so it means either of the condition fails?
either days part or property check
which one is failing? did you check
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 01:03 AM
Hi Ankur,
When I'm giving only duration.getDayPart() >days in the if condition working as expected. But it is not working when I'm giving this property condition in this business rule.
IF Due date is 01-01-2021. then satisfying duration.getDayPart() >days and updating assessment state as cancelled.
But when I'm adding property,
if (duration.getDayPart() > days && gs.getProperty('propert_name1').toString() != "true")
Then state should not cancel. But in this scenario state is getting cancelled.
propert_name1 - added 4 metric type sys id in the value field of the property
If Assessment metric type is any of this 4 then state should not change to cancel even duration.getDayPart() > days is true.
Regards,
sruthi
Regards,
sruthi