Setting Date format using flow

RudhraKAM
Tera Guru

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 

RudhraKAM_0-1689871143538.png

 

FLow 

 

RudhraKAM_1-1689871171333.png

 

How to set these formats same ? Cannot change any thing global

 

4 REPLIES 4

Riya Verma
Kilo Sage
Kilo Sage

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);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hello @Riya Verma  How to / where to check if the variable has correct format or not ?

 

On variables (front end)

RudhraKAM_0-1689873068377.png

 

Instead of BR , can we script it in Flow ?

 

Yes You can create custom Flow action and add this script to the same.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Can we script in the variable it self instead of Action ?