- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 02:56 AM - edited 01-22-2025 03:03 AM
Hi All,
Requirement:
Populate a date field in a table with the current date when the XYZ field has a specific value. Additionally, users should be able to modify the date field if needed.
To achieve this, I have created a UI Policy with the condition that the XYZ field matches the specified value.
In the UI Policy Script field, I added the following script:
Question:
Is this the correct approach?
Currently, the field is being populated, but not in the desired format. it is populated as below screenshot:
Expected Outcome:
The field should be populated with the current date in the format dd/mm/yyyy hr:mm:ss (e.g., 22/01/2025 16:47:56).
Can someone help me achieve this?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 04:04 PM
Hi All,
I used the client script with the following codes and it worked the way I wanted. Though of sharing it as it might be helpful for others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 05:05 AM
Hi @Sandhya23 ,
Can you try below code.
function onCondition() {
var currentDate = new Date(); // Get the current date and time
var year = currentDate.getFullYear();
var month = String(currentDate.getMonth() + 1).padStart(2, '0');
var day = String(currentDate.getDate()).padStart(2, '0');
var hours = String(currentDate.getHours()).padStart(2, '0');
var minutes = String(currentDate.getMinutes()).padStart(2, '0');
var seconds = String(currentDate.getSeconds()).padStart(2, '0');
// Create the formatted date string
var formattedDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
// Set the value of the field
g_form.setValue('actual_delivery_date', formattedDate);
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 04:04 PM
Hi All,
I used the client script with the following codes and it worked the way I wanted. Though of sharing it as it might be helpful for others.