Setting Date format using flow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 09:44 AM
We have a catalog item in which we have a variable with Date time format , up on creating a request we need to set that variable to Sc_task requested by ( date time format ) , pretty straight forward , but for some reason It is not setting the Time ,
on Task
FLow
How to set these formats same ? Cannot change any thing global
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 09:58 AM
HI @RudhraKAM ,
Hope you are doing great.
First, we need to ensure that the variable in the catalog item has the correct Date time format specified.
- navigate to the catalog item's form in the ServiceNow platform, and check the variable's settings. Make sure the Date time format is set correctly to capture both date and time.
- If the Date time format is already correct, and the time is still not being set properly, we can create a Business Rule to handle this scenario. Business Rules in ServiceNow allow us to run scripts when specific conditions are met.
Sample Business Rule script that will set the time for the variable upon request creation:
// Business Rule Name: Set Time for Catalog Item Variable
// Table: sc_req_item
(function executeRule(current) {
// Get the requested date from the variable
var requestedDateTime = current.variables.variable_name; // Replace "variable_name" with the actual variable name.
// Check if the variable value is a valid date and time
if (gs.nil(requestedDateTime)) {
return; // Exit the script if the value is not valid
}
var currentDateTime = new GlideDateTime();
requestedDateTime.setGlideDateTime(currentDateTime);
current.variables.variable_name = requestedDateTime; // Replace "variable_name" with the actual variable name.
})(current);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 10:11 AM
Hello @Riya Verma How to / where to check if the variable has correct format or not ?
On variables (front end)
Instead of BR , can we script it in Flow ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 10:20 AM
Yes You can create custom Flow action and add this script to the same.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 12:14 PM
Can we script in the variable it self instead of Action ?