Setting a date field to today's date when another field is set to option b. Need help with script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 08:02 AM
Hi,
The requirement is to create a new field called 'Governance date' which defaults to today's date. It has to be visible on the tm_test form but only when another field 'suitable for ATF'=no.
I have been able to do that using UI policy. When a new record is created on tm_test table and you toggle with the suitable for ATF field then the governance date field gets autofilled with today's date and is working as expected.
But for the pre-existing records if you toggle the 'suitable for ATF' field from non/yes/no then only the governance date field gets visible but it doesn't get filled by today's date.
Someone suggested I need to write a fix script for it, which I have. It has set all the preexisting ones which were 'Suitable for ATF'=no to show that field and fill with today's date, but if the choice of suitable for ATF is none on a pre existing record and you set it to no then governance date does not get filled out, only becomes visible. Here is the fix script below
var gr = new GlideRecord('tm_test');
gr.addQuery('u_suitable_for_atf', "no");
gr.query();
while (gr.next()) {
var gdt = new GlideDateTime().getDate();
gr.setValue('u_governance_review_date', gdt.toString());
gr.update();
}
What can I do so that when you toggle the suitable for ATF field from none/yes to no then the governance field not only becomes visible but gets filled out too?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2023 05:16 AM
Hi,
Can you share a copy of the UI policy you created? Also, what type of field is the ‘Suitable for ATF’ and available options?
Thanks,
Craig
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2023 09:09 AM
Hello @snow_beginner,
Can you please tell me how the date is auto-populated, may be we have to fine tune that.
Fix script will update all the existing records with the current date, not sure if that is what you wanted.
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks!!