What format to use in a sys property to pass it to Wait For of the Flow Sub ?

Romain1
Tera Contributor

Hi,

 

I try to pass the value of my system property to the "Wait for" value of this subflow : 

Flow.PNG

 

Data Pill Picker "Wait for" accepts the data type "Duration" but I don't know in which format to write it in my sys property ?

 

Here is the script of my action "Get System Property" : 

script.PNG

I try to use the example with the  GlideDuration class  : https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/c_GlideDurationScopedAPI

By setting my sys property string value at : 60000 

And I get this error when launching the flow : 

error.PNG

Does anyone have an idea of the format I should use in my sys property or an example?

Regards.

 

3 REPLIES 3

nayanawadhiya1
Kilo Sage

Hello,

Pass the value in seconds.

Don't convert the value in duration.

Use parseInt in the script action.

 

Regards,

Nayan Awadhiya

Hello, 

Thank you for your answer.

I have changed the configuration of the Sys Property at 10 seconds : 

sys_prop_conf_seconds.PNG

And modify my script action : 

parseInt.PNG

And I tested with two different configurations, an output type set to "Duration" and "Integer" and I get this result when I test the flow:

NaN_result_flow.PNG

 

The correct result should be : 

static_result.PNG

Here is a test done with the selector : 

static_conf_flow.PNG

 

Do you have an idea why do I get "NaN" in the flow response?

Thanks in advance.

dwl9898
Tera Contributor

To use a data pill for a 'Wait for' value in a Flow it has to be a data pill of variable type 'Duration'.  So when you create your action make sure to return a Duration variable.  Now what format goes into the Duration you ask?  A string, but not just any string.  It must be a date formatted string expressed as the amount of time from the date "1970-01-01 00:00:00".  This date, January 1, 1970 is known as the epoch date, and is is used on all Linux based systems as a reference to measure system time.

 

So to represent 5 minutes duration the string would look like this:
"1970-01-01 00:05:00"
 
My recommendation is to do two things:
1. Create a generic ServiceNow Action that will pull the value of any system property.
2. Create a generic SerivceNow Action that will set any minute, hour, or day duration.  In your Flow use your output from the system property Action on Step 1 as an input to this Action.
 
These two Actions can then be used across any number of Flows that you may create, and you'll find that you use them frequently.
 
Example Get-System Property Script Action:
dwl9898_0-1729713940158.png

 

Here is an example how to create the Set-Duration Action below.  The Action has 3 inputs: hours, minutes, and days respectively:

dwl9898_4-1729715475513.png

 

//Example of the Script Step: 

 

(function execute(inputs, outputs) {
  var epochDate = "1970-01-01 00:00:00";
  var hrs, mins, days;
  var dString = '';
  var minsOffset = 60;
  var hrsOffset = minsOffset * 60;
  var daysOffset = hrsOffset * 24;

  // Parse inputs
  if (inputs.hours){
    hrs = parseInt(inputs.hours);
  }
  if (inputs.minutes){
    mins = parseInt(inputs.minutes);
  }
  if (inputs.days){
    days = parseInt(inputs.days);
  }

  // Calc offset
  var offset = 0;
  if (mins) {
    offset += mins * minsOffset;
  }
  if (hrs) {
    offset += hrs * hrsOffset;
  }
  if (days) {
    offset += days * daysOffset;
  }
 
  // Update Epoch date to offset duration
  var dObj = new GlideDateTime(epochDate);
  dObj.addSeconds(offset);
  dString = dObj.toString();
 
  // Output
  outputs.value = dString;
 
})(inputs, outputs);
 
// End script ********************************
 
While this script activity itself will output a variable 'value' of type String, remember to pull the 'value' data pill into a variable of type DURATION for the output of the Action itself.
 
dwl9898_2-1729715141348.pngdwl9898_3-1729715198322.png

Now your output 'value' of type Duration data pill can be selected and placed into your 'Wait For' activity as an Explicit Duration.