<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mayank Goyal</title>
    <description>The latest articles on DEV Community by Mayank Goyal (@imtrinity94).</description>
    <link>https://dev.to/imtrinity94</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F666485%2F719c75b2-7a35-4918-b181-8d845fca5462.png</url>
      <title>DEV Community: Mayank Goyal</title>
      <link>https://dev.to/imtrinity94</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imtrinity94"/>
    <language>en</language>
    <item>
      <title>Automated Installation of vRO Plugin using Python</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Fri, 15 Apr 2022 05:08:05 +0000</pubDate>
      <link>https://dev.to/imtrinity94/automated-installation-of-vro-plugin-using-python-22e</link>
      <guid>https://dev.to/imtrinity94/automated-installation-of-vro-plugin-using-python-22e</guid>
      <description>&lt;p&gt;If you are looking for a way to quickly install plugins in your vRealize Orchestrator &lt;code&gt;(.dar or .vmoapp&lt;/code&gt; files), you can try this python script which uses vRO ControlCenter API at its core.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Python 3 installed&lt;/li&gt;
&lt;li&gt;Download the plugin that you want to install to a local folder. For demo purpose, you can download a small plugin called JsonPath from &lt;a href="https://cloudadvisors.net/wp-content/uploads/2016/05/o11nplugin-jsonpath-1.0.2.zip"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;vRO Control Center credentials&lt;/li&gt;
&lt;li&gt;Copy &lt;strong&gt;&lt;a href="https://gist.github.com/imtrinity94/38ca08e7253e404a95386e56ff9be6fc"&gt;vRO_Install_Plugin_via_Python_1.0.py&lt;/a&gt;&lt;/strong&gt; which is available at &lt;a href="https://gist.github.com/imtrinity94/38ca08e7253e404a95386e56ff9be6fc"&gt;https://gist.github.com/imtrinity94/38ca08e7253e404a95386e56ff9be6fc&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Understand the process&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;For demo purpose, I will show the very few steps that you need to install a vRO plugin named JsonPath in an automated fashion.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy the full path of downloaded plugin with filename itself. 

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C:\Users\x213816\Downloads\cloudblogger tutorial\o11nplugin-jsonpath-1.0.2.vmoapp&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7HJJWaWj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-7.png%3Fw%3D735" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7HJJWaWj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-7.png%3Fw%3D735" alt="" width="735" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep &lt;strong&gt;FQDN&lt;/strong&gt; of vRO and vRO Control Center root &lt;strong&gt;credentials&lt;/strong&gt; handy.&lt;/li&gt;
&lt;li&gt;Go to Visual Studio Code or your choice of IDE to run the &lt;strong&gt;&lt;a href="https://gist.github.com/imtrinity94/38ca08e7253e404a95386e56ff9be6fc"&gt;vRO_Install_Plugin_via_Python_1.0.py&lt;/a&gt;&lt;/strong&gt; python script. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LiCtlhUL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-8.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LiCtlhUL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-8.png%3Fw%3D1024" alt="" width="880" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Run&lt;/strong&gt; ► and provide values for asked fields&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D0Uxrftj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/2022-04-15-11_16_32-launchpad-75.154.146.35-remote-desktop-connection-1.jpg%3Fw%3D953" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D0Uxrftj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/2022-04-15-11_16_32-launchpad-75.154.146.35-remote-desktop-connection-1.jpg%3Fw%3D953" alt="" width="880" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reload&lt;/strong&gt; vRO ControlCenter, the desired plugin will be already installed there.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vHlPJ4eK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-9.png%3Fw%3D924" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vHlPJ4eK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-9.png%3Fw%3D924" alt="" width="880" height="58"&gt;&lt;/a&gt;&lt;/p&gt;




</description>
      <category>article</category>
      <category>tutorial</category>
      <category>automation</category>
      <category>plugin</category>
    </item>
    <item>
      <title>vRO Bullets</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Fri, 08 Apr 2022 10:42:02 +0000</pubDate>
      <link>https://dev.to/imtrinity94/vro-bullets-m59</link>
      <guid>https://dev.to/imtrinity94/vro-bullets-m59</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Encrypted Strings: Before being stored in vRO’s database, the AES-CBC algorithm is used to encrypt the contents of the string. (AES here on Wikipedia). An Initialization Vector (IV) is used as a key to encrypt and decrypt the data.&lt;/li&gt;
&lt;li&gt;Two XML parsers are available in vRealize Orchestrator: DOM (legacy) and E4X (dot notation). However, it is strongly recommended to use only E4X. 
Note: This parser is now deprecated by Mozilla foundation, but as the Rhino engine version used by vRealize Orchestrator is not the latest version, it is safe to use it.&lt;/li&gt;
&lt;li&gt;Orchestrator runs the code in scriptable task elements in a context that is not the Rhino root context. Orchestrator transparently wraps scriptable task elements and actions into JavaScript functions, which it then runs. A scriptable task element that contains &lt;code&gt;System.log(this);&lt;/code&gt; does not display the global object this in the same way as a standard Rhino implementation does.&lt;/li&gt;
&lt;li&gt;You can only call actions that return nonserializable objects from scripting, and not from workflows. To call an action that returns a nonserializable object, you must write a scriptable task element that calls the action by using the &lt;code&gt;System.getModule("module.name").action_name()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;For intensive Presentation Layer operations, there is a cache that you can use to put something into cache or retrieve from cache, this improves performance at an incremental scale. Methods that can be used to access cache are &lt;code&gt;putInCache&lt;/code&gt; &amp;amp; &lt;code&gt;getFromCache&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For workflows that require pausing or sleeping:
For short sleeps, you only need to do a System.sleep() to avoid serializing and deserializing the workflow inputs, attributes, and so on. -&amp;gt; Consumes Mem &amp;amp; CPU cycles for waiting.
Sleeping for an extended period of time should be done with a Workflow sleep, by using a Waiting Timer versus a sleep within a scriptable task. -&amp;gt; Saves WF state in vRO Database while waiting.&lt;/li&gt;
&lt;li&gt;XML type is not automatically serialized by vRealize Orchestrator between workflows or actions, it must be converted to string before being used as output of a workflow.
&lt;code&gt;var xmlString = xmlObj.toXMLString();&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Command-Line Utility: You can use the Orchestrator command-line utility to automate the Orchestrator configuration. Access the command-line utility by logging in to the Orchestrator Appliance as root over SSH. The utility is located in &lt;code&gt;/var/lib/vco/tools/configuration-cli/bin&lt;/code&gt;. To see the available configuration options, run &lt;code&gt;./vro-configure.sh --help&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;vRealize Orchestrator is bundled with a fluentd-based logging agent. The agent collects and stores logs so that they can be included in a log bundle and examined later. You can configure the logging agent to continuously forward vRealize Orchestrator logs to vRLI/Syslog servers by using the supplied vracli command line utility (&lt;code&gt;vracli vrli --help&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;vRealize Orchestrator now ships with cryptographic modules that have successfully passed NIST FIPS 140-2 Cryptographic Module Validation Program (CMVP) testing. When these modules are configured to run in ‘FIPS-mode’, they will cover all cryptographic operations in the product that perform a security function and/or process sensitive data.&lt;/li&gt;
&lt;li&gt;The maximum size for a Resource Element in vRealize Orchestrator is 16 MB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article is copied from &lt;a href="https://cloudblogger.co.in/"&gt;https://cloudblogger.co.in/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vro</category>
      <category>javascript</category>
      <category>vrealizeorchestrator</category>
    </item>
    <item>
      <title>Generate vRO Workflow Runs Report in CSV</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Tue, 05 Apr 2022 10:09:25 +0000</pubDate>
      <link>https://dev.to/imtrinity94/generate-vro-workflow-runs-report-in-csv-27g6</link>
      <guid>https://dev.to/imtrinity94/generate-vro-workflow-runs-report-in-csv-27g6</guid>
      <description>

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; Download the package from &lt;a href="https://developer.vmware.com/web/dp/samples?id=7884"&gt;here&lt;/a&gt; &amp;amp; edit the inputs and run it to get a CSV Report for last 30 days of Workflow Runs in vRealize Orchestrator.&lt;/p&gt;




&lt;p&gt;Many a times, we have environments where we want to monitor the executions of vRealize Orchestrator Workflows, like how many times a workflow is run, who executed the workflow, or what was the success rate of a particular workflow, or maybe just want to check how long it take to execute a workflow. I have seen few customers that were looking for similar solutions. So, If you are also looking for a way to achieve something similar, this article could be of some help.&lt;/p&gt;

&lt;p&gt;As we know, vRO offers REST API out-of-the-box for all kind of operations. Same is true for getting the facts and figures of its workflow execution. There are various ways to get that kind of information but I find using the &lt;strong&gt;catalog-service-controller&lt;/strong&gt; module to be the quickest for my use-case. Let’s see it in detail below.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Understand the REST API&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;catalog-service-controller&lt;/strong&gt; module is quite a versatile API module in vRO. You can use it to dig-in information for a extensive set of entities. However, the path and method we are mostly interested in today is, &lt;strong&gt;GET /api/catalog/{namespace}/{type}&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zHW24bw5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-5.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zHW24bw5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-5.png%3Fw%3D1024" alt="" width="880" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Path with attributes&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/api/catalog/System/WorkflowToken?conditions=state%5Ecompleted%7Cfailed&amp;amp;conditions=endDate%3E"+date30DaysAgo+"&amp;amp;conditions=endDate%3C"+currentDate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;strong&gt;&lt;em&gt;date30DaysAgo&lt;/em&gt;&lt;/strong&gt; will get its value from &lt;em&gt;getDate30DaysAgo()&lt;/em&gt; action and &lt;strong&gt;&lt;em&gt;currentDate&lt;/em&gt;&lt;/strong&gt; from &lt;em&gt;getCurrentDateInISOFormat()&lt;/em&gt; action available in the &lt;a href="https://github.com/vmwarecode/vRealize-Orchestrator-Reporting---Export-Workflow-Runs-to-CSV-and-Mail/blob/0d8a1a10d8678b141db3374b2e326594bb39c3bb/WorkflowRunReport.package"&gt;vro-package&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; You can add more states to this query like &lt;strong&gt;waiting&lt;/strong&gt; , &lt;strong&gt;canceled&lt;/strong&gt; , etc. if you are interested in workflow tokens other than &lt;strong&gt;completed&lt;/strong&gt; and &lt;strong&gt;failed&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Understand the Code&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the package attached, we have a workflow &lt;strong&gt;Workflow Runs Report Generation&lt;/strong&gt; which will have the code divided in 3 parts. For ease of operation, the workflow is creating a transient REST host using user provided inputs but you can also add your vRO as a REST Host in the inventory and add &lt;a href="https://cloudblogger.co.in/2022/04/05/generate-vro-workflow-runs-report-in-csv/#REST-URL"&gt;this REST URL&lt;/a&gt; as a REST Operation with dates as variable input. Also, in Part 2/3, only 5 properties are added to the CSV data. You can lookup for additional properties related to a workflow token if you want a more details-heavy report.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Part 1/3: Invoke Rest Operation
.
.
.

//Part 2/3: Gather data in CSV format
var reportCSV = "Name,Status,Start Date,End Date,Started by\r\n";
if (response.statusCode != 200) { // 200 - HTTP status OK
    System.warn("Request failed with status code " + response.statusCode);
} else {
    var doc = JSON.parse(response.contentAsString);
    System.log("Number of failed or cancelled tokens: " + doc.total);
    for each(var link in doc.link) {
        for each(var attribute in link.attributes) {
            if (attribute.name == "name")
                var wfName = attribute.value;
            if (attribute.name == "state")
                var wfState = attribute.value;
            if (attribute.name == "startDate")
                var wfStartDate = attribute.value;
            if (attribute.name == "endDate")
                var wfEndDate = attribute.value;
            if (attribute.name == "startedBy")
                var wfStartedBy = attribute.value;
        }
        reportCSV += (wfName + "," + wfState + "," + wfStartDate + "," + wfEndDate + "," + wfStartedBy+"\r\n");
    }
}

//Part 3/3: Send CSV data as a mail attachment
.
.
.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Part 3/3, we are simply attaching the CSV data as a MIME attachment and send it to the &lt;strong&gt;toAddress&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let’s Run it&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Import the package available &lt;a href="https://github.com/vmwarecode/vRealize-Orchestrator-Reporting---Export-Workflow-Runs-to-CSV-and-Mail/blob/0d8a1a10d8678b141db3374b2e326594bb39c3bb/WorkflowRunReport.package"&gt;here&lt;/a&gt;. If you need help with package import, follow this guide &lt;a href="https://docs.vmware.com/en/vRealize-Orchestrator/8.0/com.vmware.vrealize.orchestrator-using-ops-client.doc/GUID-CE405299-1800-40C0-9054-5C032A5B022C.html"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Go to workflow &lt;strong&gt;Workflow Runs Report Generation&lt;/strong&gt; and Click &lt;strong&gt;Edit&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Go to the scriptable task and edit these input values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BLQe6j8s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-6.png%3Fw%3D486" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BLQe6j8s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-6.png%3Fw%3D486" alt="" width="486" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After editing the values, &lt;strong&gt;Save&lt;/strong&gt; it. &lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Run&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A-yO1G1X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A-yO1G1X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image.png%3Fw%3D1024" alt="" width="880" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the workflow executed successfully, you will see in the logs, the mail is being sent to the provided email address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HfPwFErL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-1.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HfPwFErL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-1.png%3Fw%3D1024" alt="" width="880" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check your mailbox. If you can’t see the email in your inbox, probably check the email address that you’ve provided or check your &lt;strong&gt;SPAM&lt;/strong&gt; folder.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R9ZNKym1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-2.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R9ZNKym1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-2.png%3Fw%3D1024" alt="" width="880" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the attached CSV file and Open it. You will see a sheet which will be identical to what you have in your vRO &lt;strong&gt;Workflow Runs&lt;/strong&gt; Tab &lt;em&gt;(Performance view OFF)&lt;/em&gt;. You may also want to sort this sheet on &lt;strong&gt;Start Date&lt;/strong&gt; column in descending manner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gz_qSXXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-4.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gz_qSXXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-4.png%3Fw%3D1024" alt="" width="880" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LlChisHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-3.png%3Fw%3D725" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LlChisHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/04/image-3.png%3Fw%3D725" alt="" width="725" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Download vRO Package&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/vmwarecode/vRealize-Orchestrator-Reporting---Export-Workflow-Runs-to-CSV-and-Mail/blob/0d8a1a10d8678b141db3374b2e326594bb39c3bb/WorkflowRunReport.package"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ACKTP-l2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/01/92813512-27f0bb80-f376-11ea-8562-ee2b3e416aec-2.png%3Fw%3D123" alt="" width="121" height="42"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;That’s it in today’s post. I hope you will like it.&lt;/p&gt;

</description>
      <category>article</category>
      <category>tutorial</category>
      <category>package</category>
      <category>reporting</category>
    </item>
    <item>
      <title>JavaScript to Java Conversion Limitation in vRO</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Sun, 03 Apr 2022 09:15:42 +0000</pubDate>
      <link>https://dev.to/imtrinity94/javascript-to-java-conversion-limitation-in-vro-358g</link>
      <guid>https://dev.to/imtrinity94/javascript-to-java-conversion-limitation-in-vro-358g</guid>
      <description>&lt;p&gt;When vRealize Orchestrator runs scripts, the vCenter Server plug-in converts &lt;strong&gt;JavaScript arrays&lt;/strong&gt; to &lt;strong&gt;Java arrays of a fixed size&lt;/strong&gt;. As a result, you cannot add new values to vCenter Server data objects that take arrays as property values. You can create an object that takes an array as a property if you instantiate that object by passing it a pre-filled array. However, after you instantiate the object, you cannot add values to the array.&lt;/p&gt;

&lt;p&gt;For example, the following code does not work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var spec = new VcVirtualMachineConfigSpec();
spec.deviceChange = [];
spec.deviceChange[0] = new VcVirtualDeviceConfigSpec();
System.log(spec.deviceChange[0]); //Output undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, vRealize Orchestrator converts the empty  &lt;strong&gt;spec.deviceChange&lt;/strong&gt;  JavaScript array into the fixed-size Java array &lt;strong&gt;VirtualDeviceConfigSpec[]&lt;/strong&gt; before it calls &lt;strong&gt;setDeviceChange()&lt;/strong&gt;. When calling &lt;strong&gt;spec.deviceChange[0] = new VcVirtualDeviceConfigSpec()&lt;/strong&gt;, vRealize Orchestrator calls &lt;strong&gt;getDeviceChange()&lt;/strong&gt; and the array remains a fixed, empty Java array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workaround&lt;/strong&gt; : Declare the array as a local variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var spec = new VcVirtualMachineConfigSpec();
var deviceSpec = [];
deviceSpec[0] = new VcVirtualDeviceConfigSpec();
spec.deviceChange = deviceSpec;
System.log(spec.deviceChange[0]);
/* Output
DynamicWrapper (Instance) : [VcVirtualDeviceConfigSpec]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualDeviceSpec_Wrapper] -- VALUE : (vim.vm.device.VirtualDeviceSpec) {
   dynamicType = null,
   dynamicProperty = null,
   operation = null,
   fileOperation = null,
   device = null,
   profile = null,
   backing = null
}
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;







&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt; This article is drawn from Release Notes of vRealize Orchestrator 8.x and is added here just for educational purposes.&lt;/p&gt;




</description>
      <category>article</category>
      <category>api</category>
      <category>minipost</category>
      <category>vro</category>
    </item>
    <item>
      <title>Basics of REST</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Sun, 03 Apr 2022 08:53:39 +0000</pubDate>
      <link>https://dev.to/imtrinity94/basics-of-rest-34ke</link>
      <guid>https://dev.to/imtrinity94/basics-of-rest-34ke</guid>
      <description>&lt;p&gt;So what is &lt;a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm"&gt;REST&lt;/a&gt;? At a high level REST, or REpresentational State Transfer, is an architectural style for distributed hypermedia ystems. It was created from a combination of other architectural styles and enlists several constraints. Roy Fielding, its creator, said that “REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems.”&lt;/p&gt;

&lt;p&gt;This guide will cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REST HTTP requests&lt;/li&gt;
&lt;li&gt;REST HTTP responses&lt;/li&gt;
&lt;li&gt;Constraints needed for an API to be RESTful&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Requests&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The client has to make a request to the server to get or modify data on the server. A request contains the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP verb&lt;/li&gt;
&lt;li&gt;headers&lt;/li&gt;
&lt;li&gt;path: to a resource&lt;/li&gt;
&lt;li&gt;[optional] message body: data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider the example of a todo list. An example request could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /todos
Accept: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;HTTP Methods/Verbs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;HTTP methods, or verbs, define what kind of operation to perform on a resource. Some of the primary ones used with RESTful APIs are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;GET&lt;/code&gt;: get a resource or collection of resources&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;POST&lt;/code&gt;: create a new resource&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PUT&lt;/code&gt;: update a resource&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PATCH&lt;/code&gt;: partially modify a resource&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DELETE&lt;/code&gt;: delete a resource&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;HTTP Headers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The client uses headers to pass along request information to the server. Requests can have an &lt;code&gt;Accept&lt;/code&gt; request HTTP header which specifies what content type the client can accept from the server. The values are of the media, or &lt;a href="https://www.iana.org/assignments/media-types/media-types.xhtml"&gt;MIME type&lt;/a&gt;. The simplest MIME types are of the format &lt;code&gt;type/subtype&lt;/code&gt;. For example, this could be &lt;code&gt;text/html&lt;/code&gt; which is for a text file containing HTML. Or &lt;code&gt;application/json&lt;/code&gt; for a JSON file. To see a list of common &lt;code&gt;Accept&lt;/code&gt; values check out the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types"&gt;MDN web docs&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Path&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Requests need to contain a path to the resource it is trying to perform the HTTP request on. In the above example, that is &lt;code&gt;/todos&lt;/code&gt;. This is the resource that you are looking to read from or write to.&lt;/p&gt;

&lt;p&gt;One important thing to note is the difference between addressing a collection and an individual item in that collection. The path &lt;code&gt;/todos&lt;/code&gt; would be addressing all of the items on the todo list. A &lt;code&gt;POST&lt;/code&gt; to this path could create a new item on that list, and a request to &lt;code&gt;GET /todos&lt;/code&gt; would return all items. On the other hand, &lt;code&gt;GET /todos/2&lt;/code&gt; would return just the second item on the todo list.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Response&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;After the client sends a request to the server, the server sends a response back to the client. This response consists of a: status code headers message body: data&lt;/p&gt;

&lt;p&gt;For the previous request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /todos
Accept: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response could contain the following for a successful request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "name": "pay rent",
        "due": 1589031653,
        "completed": false
    },
    {
        "name": "get groceries",
        "due": 1588869295,
        "completed": true
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;HTTP Headers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The responses have a &lt;code&gt;Content-Type&lt;/code&gt; entity header which specifies the MIME type of the resource. Its value should match one of the &lt;code&gt;Accept&lt;/code&gt; types sent by the client. In the above example, both the &lt;code&gt;Content-Type&lt;/code&gt; and &lt;code&gt;Accept&lt;/code&gt; header values are &lt;code&gt;application/json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Headers can contain information on a wide array of topics including how to handle the TCP connection, authentication, caching, and more. Some REST APIs may have headers specific to them, but there’s also some headers that have a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers"&gt;universal definition&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Response Status Code&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;One of the return values in a response is a response status code. Each code has a specific designation; for example, &lt;code&gt;200&lt;/code&gt; is &lt;code&gt;OK&lt;/code&gt; and means the request was successful. The response code categories are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;1XX&lt;/code&gt;: Informational&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2XX&lt;/code&gt;: Successful&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;3XX&lt;/code&gt;: Redirects&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;4XX&lt;/code&gt;: Client Errors&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;5XX&lt;/code&gt;: Server Errors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To see the detailed list of response codes and their meaning, check out the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status"&gt;MDN web docs&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Body&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The body contains the data the client requested in the MIME type specified in the &lt;code&gt;Content-Type&lt;/code&gt; header. In the example above, the body of the response is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    {
        "name": "pay rent",
        "due": 1589031653,
        "completed": false
    },
    {
        "name": "get groceries",
        "due": 1588869295,
        "completed": true
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Constraints&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In order to create RESTful APIs, they need to adhere to six style constraints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Client-Server Separation&lt;/li&gt;
&lt;li&gt;Stateless&lt;/li&gt;
&lt;li&gt;Cache&lt;/li&gt;
&lt;li&gt;Uniform Interface&lt;/li&gt;
&lt;li&gt;Layered System&lt;/li&gt;
&lt;li&gt;[Optional] Code-On-Demand&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Client-Server&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, there needs to be a separation of client and server. This means that the client and server each need to work independent of each other. Their only form of interaction is when a client makes requests and a server sends a response whenever it receives a request. One of the benefits is that the client and server can each be updated or modified independently without affecting the other.&lt;/p&gt;

&lt;p&gt;For example, if you make a call to a restaurant to place a takeout order, the only interaction is you asking for a specific item and them responding with an ok or saying they don’t have it.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Stateless&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, the client and server communication needs to be stateless: the server and client don’t need to know the state of the other. The server doesn’t store state from the client and therefore the client can’t depend on it. Therefore the client needs to send everything the server would need to process a request every time and any storing needs to happen client-side.&lt;/p&gt;

&lt;p&gt;To continue with the analogy, when you make your call, you don’t need to know what the restaurant has in stock, and they don’t need to know what you want until you order. Additionally, you’re responsible for keeping track of what you like to order, not the restaurant.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Cache&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Cache constraints require that the response be labeled as cacheable or non-cacheable. If it’s cacheable, then the client can choose to use this data for future requests that are equivalent. For instance, if the data is valid for a set time, the cached data will be used instead of making a request to the server.&lt;/p&gt;

&lt;p&gt;For your takeout call, the restaurant may tell you that a specific item is not available until a certain date. You can then remember to not order it again if you make another request before that date.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Uniform Interface&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As mentioned, the client and server are independent of each other, meaning they evolve and change independently. For this reason, it’s imperative that the interface between the client and server expect some commonality in their communication. This constraint can actually be broken down even further:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Resource-Based&lt;/strong&gt; : This is two-fold: First, individual resources should be identifiable in the request. Often this is done in the path of the URI of the request. For example, &lt;code&gt;/todos/2&lt;/code&gt; would directly address the &lt;code&gt;todo&lt;/code&gt; item with the ID of &lt;code&gt;2&lt;/code&gt;. Second, the presentation of the resource does not necessarily need to match the internal representation by the server. The &lt;code&gt;todo&lt;/code&gt; item may be returned as JSON, but more realistically the server is storing this in a database in another format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manipulate Resources Through Representations&lt;/strong&gt; : When the client receives a resource, the representation of that resource contains enough information to update or delete it. This could be seen as the flip-side of the “stateless” constraint. Using the same example of a todo list, if a client requests all items in a todo list, each of those items would likely include an ID so that it could be individually addressed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Self-Descriptive Messages&lt;/strong&gt; : Each message or resource should include enough information so that the client knows how to process that message. For example, if a client has requested a resource that’s returned as JSON, the response should also include a &lt;code&gt;Content-Type&lt;/code&gt; header with the value &lt;code&gt;application/json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hypermedia as the Engine of Application Sate&lt;/strong&gt; : AKA &lt;a href="https://en.wikipedia.org/wiki/HATEOAS"&gt;“HATEOAS”&lt;/a&gt;. This could be a whole conversation on it’s own, and it’s encouraged to read on this topic as well, but in short each response should include related links that the client can use to discover other actions and resources. Continuing the ToDo example, requesting an individual todo item may include links to the list that it is a part of.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Layered System&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Layered system constraints are used to scope hierarchical layers based on behavior and have each layer be unable to have visibility past the layer it is interacting with. That’s to say, a client may send a request to a server, which in turn may send a request to a data service, which sends a request to an authentication service. All of this is invisible to the client and the client can not and should not distinguish between a direct request to the data or one that has multiple requests server-side. This is also true for infrastructure and operational components such as proxies and load balancers. Introducing these components to the server architecture should require no updates from the client.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;[Optional] Code-On-Demand&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This constraint states that a server can extend the functionality of a client by providing it executable code. Probably the most common example of this is client-side scripting with JavaScript, but this can take many forms. While this keeps clients simpler and smaller, it also reduces visibility of features and can introduce ambiguity. Because of this, while the absence of other constraints may mean a service isn’t actually RESTful, this constraint is optional.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Well, this is the end of this coverage of the basics of REST. Reading Roy Fielding’s REST &lt;a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm"&gt;dissertation&lt;/a&gt; is a great place to start if you haven’t already.&lt;/p&gt;

</description>
      <category>article</category>
    </item>
    <item>
      <title>Working with Date and Time in vRO</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Sat, 19 Mar 2022 05:56:00 +0000</pubDate>
      <link>https://dev.to/imtrinity94/working-with-date-and-time-in-vro-49ah</link>
      <guid>https://dev.to/imtrinity94/working-with-date-and-time-in-vro-49ah</guid>
      <description>&lt;p&gt;Manipulation of Date &amp;amp; Time is overwhelmingly difficult. Mostly because there are so many formats, standards and handling techniques. Being a vRO programmer, you can’t run away from this date manipulation, be it for Reports creation, REST Calls, Data fetching or Interacting with other servers. Ask any programmer about their experience handling dates and time zones and they will probably share some war stories. Handling date and time fields is certainly not rocket science but can often be tedious and error-prone.&lt;/p&gt;

&lt;p&gt;In this article, we will explore some of the key concepts that are necessary for manipulating date and time values correctly, formats that are convenient for storing DateTime values and transferring them over APIs, and more.&lt;/p&gt;

&lt;p&gt;If you are sending and receiving data through a REST API, you will eventually need to convert the date to a string and vice versa because JSON doesn’t have a native data structure to represent DateTime. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Intrinsic&lt;/strong&gt; &lt;strong&gt;Date() Class&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;vRO provides a Date() class to satisfy almost all the date and time hunger. It has a constructor that takes variety of inputs to start off. There are various methods and functions take allows quick shape-shifting of date and time. However, It may lack some quirky features that you may look out for. Let’s start off by taking a look at this Date class in a more comprehensive way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5IDUQC7b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/datetime-4.png%3Fw%3D1000" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5IDUQC7b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/datetime-4.png%3Fw%3D1000" alt="" width="880" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It starts here. You call the constructor and you will get the current date and time. BOOM! &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mU9Mft3b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f680.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mU9Mft3b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f680.png" alt="🚀" width="72" height="72"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentDate = new Date();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don’t pass anything to the Date constructor, the date object returned contains the current date and time.&lt;/p&gt;

&lt;p&gt;You can then format it to extract only the date part as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentDate = new Date();
const currentDayOfMonth = currentDate.getDate();
const currentMonth = currentDate.getMonth(); // Be careful! January is 0, not 1
const currentYear = currentDate.getFullYear();
const dateString = currentDayOfMonth + "-" + (currentMonth + 1) + "-" + currentYear;
System.log(dateString)
//Output = "19-03-2022"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Caution&lt;/strong&gt; It’s not &lt;code&gt;getYear()&lt;/code&gt;, but &lt;code&gt;getFullYear()&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;If you instead want to get the current time stamp, you can create a new Date object and use the getTime() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentDate = new Date();
const timestamp = currentDate.getTime();
System.log(timestamp); // 1647678776796
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt; In JavaScript, a time stamp is the number of milliseconds that have passed since January 1, 1970, which is also known as Unix/ECMAScript Epoch format.&lt;/p&gt;




&lt;p&gt;You can also take an input of Type &lt;strong&gt;Date&lt;/strong&gt; in workflow or action and handle it in your scripts just like any other Date object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ROqcFyV3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-47.png%3Fw%3D343" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ROqcFyV3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-47.png%3Fw%3D343" alt="" width="343" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Parsing a Date&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Converting a string to a JavaScript date object is done in different ways.&lt;/p&gt;

&lt;p&gt;The Date object’s constructor accepts a wide variety of date formats:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date1 = new Date("Wed, 27 July 2016 13:30:00");
const date2 = new Date("Wed, 27 July 2016 07:45:00 UTC");
const date3 = new Date("27 July 2016 13:30:00 UTC+05:45");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or we can also use Date.parse(), that will return timestamp as string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var ms = Date.parse("27 July 2016 13:30:00 UTC+05:45"); 
System.log(ms); // 1469605500000 (timestamp)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that you do not need to include the day of week because JS can determine the day of the week for any date.&lt;/p&gt;

&lt;p&gt;You can also pass in the year, month, day, hours, minutes, and seconds as separate arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date = new Date(2016, 6, 27, 13, 30, 0);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or you can even pass the Unix Epoch number directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date = new Date(1647678776796);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;that means to get the zeroth timestamp i.e. Jan 1st of 1970 UTC+0, pass 0 as a parameter to Date()&lt;/p&gt;

&lt;p&gt;const date = new Date(0);&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Working with&lt;/strong&gt; &lt;strong&gt;ISO 8601 Format (YYYY-MM-DDTHH:mm:ss.SSSZ)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Of course, you can always use this specific ISO date format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6SYWuaxo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/datetime-1.png%3Fw%3D1000" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6SYWuaxo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/datetime-1.png%3Fw%3D1000" alt="" width="880" height="528"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date = new Date("2016-07-27T07:45:00.000Z"); // Fri Sep 02 2022 07:45:00 GMT-0000 (GMT)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Get Current Date in ISO complete format&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Many a times, we need Dates in a complete ISO format [YYYY-MM-DDTHH:mm:ss.SSSZ], for making REST calls etc. We can use the &lt;code&gt;toISOString()&lt;/code&gt; or &lt;code&gt;toJSON()&lt;/code&gt; methods of the Date object to convert the local DateTime to UTC.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dateFromUI = "12-13-2022";
const timeFromUI = "15:20";
const dateParts = dateFromUI.split("-");
const timeParts = timeFromUI.split(":");
const date = new Date(dateParts[2], dateParts[0]-1, dateParts[1], timeParts[0], timeParts[1]);
const dateISO = date.toISOString();
System.log(dateISO); //2022-12-13T15:20:00.000Z
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Caution&lt;/strong&gt; Not all variations of ISO 8601 format are supported by Date() constructor in vRO.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date = new Date("2016-07-27T07:45:00Z"); // Invalid Date
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;If you are sure of the format you want to use, it is best to extract individual bits using the JavaScript functions we covered above and create a string yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var currentDate = new Date();
var date = currentDate.getDate();
var month = currentDate.getMonth(); 
var year = currentDate.getFullYear();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can get the date in MM/DD/YYYY format as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var monthDateYear = (month+1) + "/" + date + "/" + year;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem with this solution is that it can give an inconsistent length to the dates because some months and days of the month are single-digit and others double-digit. This can be problematic, for example, if you are displaying the date in a table column, because the dates don’t line up.&lt;/p&gt;

&lt;p&gt;We can address this by using a “pad” function that adds a leading 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function pad(n) {
    return n&amp;lt;10 ? '0'+n : n;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we get the correct date in MM/DD/YYYY format using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mmddyyyy = pad(month + 1) + "/" + pad(date) + "/" + year;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want DD-MM-YYYY instead, the process is similar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var ddmmyyyy = pad(date) + "-" + pad(month + 1) + "-" + year;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s up the ante and try to print the date in “Month Date, Year” format. We will need a mapping of month indexes to names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var monthNames = [
    "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
];
var dateWithFullMonthName = monthNames[month] + " " + pad(date) + ", " + year;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is easy to determine the day of week from &lt;code&gt;0&lt;/code&gt; (Sunday) to &lt;code&gt;6&lt;/code&gt; (Saturday). The first day is always Sunday, so let’s add that in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var daysOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
//or
//var completeDaysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
ordinalDateWithDayOfWeek = daysOfWeek[currentDate.getDay()] + ", " + ordinalDate;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By now, you might understand how to get bits of information out of dates and how to pad them. Now, let’s create an ISO format from scratch like I have done here (contains +00:00 instead of Z as per my requirement).&lt;/p&gt;

&lt;p&gt;.gist table { margin-bottom: 0; }&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span&amp;gt;
  This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
  &amp;lt;a href="https://github.co/hiddenchars" target="_blank"&amp;gt;Learn more about bidirectional Unicode characters&amp;lt;/a&amp;gt;
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
 &lt;a href="%7B%7B%20revealButtonHref%20%7D%7D"&gt; Show hidden characters

&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;span&gt;&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
&lt;br&gt;
&lt;/span&gt;

&lt;p&gt;| | function getCurrentDateInISOFormat() { |&lt;br&gt;
| | //Desired Format 2016-06-14T00:00:00.000+03:00 |&lt;br&gt;
| | var date = new Date(); |&lt;br&gt;
| | System.log("Current Date: " + date.toGMTString()); |&lt;br&gt;
| | //yy=date.getFullYear().toString().substr(2,2); |&lt;br&gt;
| | var yyyy = date.getFullYear(); |&lt;br&gt;
| | var mm = (date.getMonth() + 1 &amp;lt; 10 ? "0" : "") + (date.getMonth() + 1); |&lt;br&gt;
| | var dd = (date.getDate() &amp;lt; 10 ? "0" : "") + date.getDate(); |&lt;br&gt;
| | var HH = (date.getHours() &amp;lt; 10 ? "0" : "") + date.getHours(); |&lt;br&gt;
| | var MM = (date.getMinutes() &amp;lt; 10 ? "0" : "") + date.getMinutes(); |&lt;br&gt;
| | var SS = (date.getSeconds() &amp;lt; 10 ? "0" : "") + date.getSeconds(); |&lt;br&gt;
| | var milli = ""; |&lt;br&gt;
| | if (date.getMilliseconds() &amp;lt; 10) |&lt;br&gt;
| | milli = "00" + date.getMilliseconds(); |&lt;br&gt;
| | else if (date.getMilliseconds() &amp;lt; 100 &amp;amp;&amp;amp; date.getMilliseconds() &amp;gt; 10) |&lt;br&gt;
| | milli = "0" + date.getMilliseconds(); |&lt;br&gt;
| | else |&lt;br&gt;
| | milli = date.getMilliseconds(); |&lt;br&gt;
| | System.log(yyyy + "-" + mm + "-" + dd + "T" + HH + ":" + MM + ":" + SS + "." + milli + "+00:00"); |&lt;br&gt;
| | return (yyyy + "-" + mm + "-" + dd + "T" + HH + ":" + MM + ":" + SS + "." + milli + "+00:00"); |&lt;br&gt;
| | } |&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/imtrinity94/470ba338ab6bb0823f310aa66309bf30/raw/5aabc3636d942cfdaf93fba1a79b2d00ede54510/vro_getCurrentDateInISOFormat.js"&gt;view raw&lt;/a&gt;&lt;a href="https://gist.github.com/imtrinity94/470ba338ab6bb0823f310aa66309bf30#file-vro_getcurrentdateinisoformat-js"&gt;vro_getCurrentDateInISOFormat.js&lt;/a&gt; hosted with ❤ by &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Get the number of seconds since the Unix/ECMAScript Epoch&lt;/strong&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var seconds = Math.floor(Date.now() / 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Working with past and future dates
&lt;/h2&gt;

&lt;p&gt;The best way to work and calculate present and future dates is by using Unix Epoch format which is conveniently the number of milliseconds after midnight January 1, 1970 till the given date expressed as a string which is IETF format. Let’s see few examples.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt; It should be noted that the maximum &lt;code&gt;Date&lt;/code&gt; is not of the same value as the maximum safe integer (&lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt; is 9,007,199,254,740,991). Instead, it is defined in ECMA-262 that a maximum of ±100,000,000 (one hundred million) days relative to January 1, 1970 UTC (that is, April 20, 271821 BCE ~ September 13, 275760 CE) can be represented by the standard &lt;code&gt;Date&lt;/code&gt; object (equivalent to ±8,640,000,000,000,000 milliseconds).&lt;/p&gt;


&lt;h3&gt;
  
  
  Get current time in milliseconds
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// vRO System method
System.getCurrentTime() //1647861957381 
//or
//Javascript method
Date.now() //1647861957381 
//or
var date = new Date(); //allows any Date to be used 
System.log(date.valueOf()); //1647861957381

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3BtRk0tw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/datetime-3.png%3Fw%3D1000" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3BtRk0tw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/datetime-3.png%3Fw%3D1000" alt="" width="880" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets say you want to fetch the date 4 days later relative to today, you can convert the today’s date in Unix Epoch format and add 4 x 24 x 60 x 60 x 1000 milliseconds to it and you will get a date exactly 4 days ahead with same time of the day, that because you have not changed enough milliseconds to modify the time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var date = new Date(); //Thu Mar 21 2022 11:42:06 GMT-0000 (GMT)
System.log(date.valueOf());
var frameOfTime = date.valueOf() + (4*24*60*60*1000);
var date = new Date(frameOfTime); //Thu Mar 25 2022 11:42:06 GMT-0000 (GMT)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s say you want to go back in time 4 hours back, You will subtract 4 x 60 x 60 x 1000 milliseconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var date = new Date(); //Thu Mar 21 2022 11:42:06 GMT-0000 (GMT)
var frameOfTime = date.valueOf() - (4*60*60*1000);
var date = new Date(frameOfTime); //Thu Mar 25 2022 07:42:06 GMT-0000 (GMT)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Comparing Dates
&lt;/h2&gt;

&lt;p&gt;First, we need to create date objects. Fortunately, &amp;lt;, &amp;gt;, &amp;lt;=, and &amp;gt;= all work. So comparing July 19, 2014 and July 18, 2014 is as easy as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date1 = new Date("July 19, 2022");
const date2 = new Date("July 28, 2022");
if(date1 &amp;gt; date2) {
    System.log("First date is more recent");
} else {
    System.log("Second date is more recent");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checking for equality is trickier, since two date objects representing the same date are still two different date objects and will not be equal. Comparing date strings is a bad idea because, for example, “July 20, 2022” and “20 July 2022” represent the same date but have different string representations. The snippet below illustrates the first point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const date1 = new Date("June 10, 2003");
const date2 = new Date(date1);
const equalOrNot = date1 == date2 ? "equal" : "not equal";
System.log(equalOrNot);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output &lt;code&gt;not equal&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This particular case can be fixed by comparing the integer equivalents of the dates (their time stamps) as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;date1.getTime() == date2.getTime();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moreover, vRO is not very good with timezones. So, the best is that we should ignore the user’s time zone and use UTC while creating the date object. There are two ways to do it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an ISO formatted date string from the user input date and use it to create a Date object. Using a valid ISO date format to create a Date object while making the intent of UTC vs local very clear.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userEnteredDate = "12/20/1989";
const parts = userEnteredDate.split("/");
const userEnteredDateISO = parts[2] + "-" + parts[0] + "-" + parts[1];
const userEnteredDateObj = new Date(userEnteredDateISO + "T00:00:00.000Z");
const dateFromAPI = new Date("1989-12-20T00:00:00.000Z");
const result = userEnteredDateObj.getTime() == dateFromAPI.getTime(); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This also works if you don’t specify the time since that will default to midnight (i.e., 00:00:00Z):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userEnteredDate = new Date("1989-12-20");
const dateFromAPI = new Date("1989-12-20T00:00:00.000Z");
const result = userEnteredDate.getTime() == dateFromAPI.getTime(); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember: If the date constructor is passed a string in correct ISO date format of YYYY-MM-DD, it assumes UTC automatically.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript provides a neat Date.UTC() function that you can use to get the UTC time stamp of a date. We extract the components from the date and pass them to the function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userEnteredDate = new Date("12/20/1989");
const userEnteredDateTimeStamp = Date.UTC(userEnteredDate.getFullYear(), userEnteredDate.getMonth(), userEnteredDate.getDate(), 0, 0, 0);
const dateFromAPI = new Date("1989-12-20T00:00:00.000Z");
const result = userEnteredDateTimeStamp == dateFromAPI.getTime();
System.log(result); //true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Finding the Difference Between Two Dates
&lt;/h2&gt;

&lt;p&gt;A common scenario you will come across is to find the difference between two dates.&lt;/p&gt;

&lt;p&gt;We discuss two use cases:&lt;/p&gt;

&lt;h3&gt;
  
  
  FINDING THE NUMBER OF DAYS BETWEEN TWO DATES
&lt;/h3&gt;

&lt;p&gt;Convert both dates to UTC time stamp, find the difference in milliseconds and find the equivalent days.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dateFromAPI = "2016-02-10T00:00:00.000Z";
const now = new Date();
const datefromAPITimeStamp = (new Date(dateFromAPI)).getTime();
const nowTimeStamp = now.getTime();
const microSecondsDiff = Math.abs(datefromAPITimeStamp - nowTimeStamp);
// Math.round is used instead of Math.floor to account for certain DST cases
// Number of milliseconds per day =
// 24 hrs/day * 60 minutes/hour * 60 seconds/minute * 1000 ms/second
const daysDiff = Math.round(microSecondsDiff / (1000 * 60 * 60 * 24));
System.log(daysDiff); //2231
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  FINDING USER’S AGE FROM THEIR DATE OF BIRTH
&lt;/h3&gt;

&lt;p&gt;Note: We have a non-standard format. Read the API doc to determine if this means 12 Oct or 10 Dec. Change to ISO format accordingly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const birthDateFromAPI = "12/10/1989";
const parts = birthDateFromAPI.split("/");
const birthDateISO = parts[2] + "-" + parts[0] + "-" + parts[1];
const birthDate = new Date(birthDateISO);
const today = new Date();
var age = today.getFullYear() - birthDate.getFullYear();
if(today.getMonth() &amp;lt; birthDate.getMonth()) {
    age--;
}
if(today.getMonth() == birthDate.getMonth() &amp;amp;&amp;amp; today.getDate() &amp;lt; birthDate.getDate()) {
    age--;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Find Execution time of a f(n)
&lt;/h2&gt;

&lt;p&gt;You can use these logics to get more purposeful result. You can calculate the execution time of a function you just created and may optimize it.&lt;/p&gt;

&lt;p&gt;.gist table { margin-bottom: 0; }&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span&amp;gt;
  This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
  &amp;lt;a href="https://github.co/hiddenchars" target="_blank"&amp;gt;Learn more about bidirectional Unicode characters&amp;lt;/a&amp;gt;
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
 &lt;a href="%7B%7B%20revealButtonHref%20%7D%7D"&gt; Show hidden characters

&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;span&gt;&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
&lt;br&gt;
&lt;/span&gt;

&lt;p&gt;| | // To test a function and get back its return |&lt;br&gt;
| | function printElapsedTime(fTest) { |&lt;br&gt;
| | var StartTime = Date.now(), |&lt;br&gt;
| | vReturn = fTest(), |&lt;br&gt;
| | EndTime = Date.now(), |&lt;br&gt;
| | difference = EndTime–StartTime |&lt;br&gt;
| | |&lt;br&gt;
| | System.log("Elapsed time: "+difference+" milliseconds") //5001 milliseconds |&lt;br&gt;
| | return vReturn |&lt;br&gt;
| | } |&lt;br&gt;
| | |&lt;br&gt;
| | var yourFunctionReturn = printElapsedTime(sort) |&lt;br&gt;
| | |&lt;br&gt;
| | function sort(){ // your function |&lt;br&gt;
| | const array1 = [1, 30, 4, 21, 100000]; |&lt;br&gt;
| | array1.sort(); |&lt;br&gt;
| | System.log(array1); |&lt;br&gt;
| | System.sleep(5000) |&lt;br&gt;
| | } |&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/imtrinity94/649bcb80ee654c30e574b1dabe89f854/raw/dd5b3b3602331891a21bd29202c981aee5f0cd4d/vRO_function_execution_time.js"&gt;view raw&lt;/a&gt;&lt;a href="https://gist.github.com/imtrinity94/649bcb80ee654c30e574b1dabe89f854#file-vro_function_execution_time-js"&gt;vRO_function_execution_time.js&lt;/a&gt; hosted with ❤ by &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Extras&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;vRO does provide various methods to represent date and time in various formats out-of-the-box. Let’s have a look on their output.&lt;/p&gt;

&lt;p&gt;.gist table { margin-bottom: 0; }&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span&amp;gt;
  This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
  &amp;lt;a href="https://github.co/hiddenchars" target="_blank"&amp;gt;Learn more about bidirectional Unicode characters&amp;lt;/a&amp;gt;
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
 &lt;a href="%7B%7B%20revealButtonHref%20%7D%7D"&gt; Show hidden characters

&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;span&gt;&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
&lt;br&gt;
&lt;/span&gt;

&lt;p&gt;| | var date = new Date(Date.UTC()); //Mon Jan 01 1900 00:00:00 GMT-0000 (GMT) |&lt;br&gt;
| | System.log(date.toString()); //Fri Aug 23 1999 14:53:51 GMT-0000 (GMT) |&lt;br&gt;
| | System.log(date.toTimeString()); //14:53:51 GMT-0000 (GMT) |&lt;br&gt;
| | System.log(date.toLocaleTimeString()); //2:53:51 PM GMT |&lt;br&gt;
| | System.log(date.toLocaleDateString());//January 6, 2009 |&lt;br&gt;
| | System.log(date.toDateString());//Tue Jan 06 2009 |&lt;br&gt;
| | System.log(date.valueOf()); //1455062400000 |&lt;br&gt;
| | System.log(date.toUTCString()); // Wed, 10 Feb 2016 00:00:00 GMT |&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/imtrinity94/3aec2c669565109922fe781117f7d724/raw/7731adcebbf983c4de02d5e212534c8238c886f2/vRO_OOB_Date_functions.js"&gt;view raw&lt;/a&gt;&lt;a href="https://gist.github.com/imtrinity94/3aec2c669565109922fe781117f7d724#file-vro_oob_date_functions-js"&gt;vRO_OOB_Date_functions.js&lt;/a&gt; hosted with ❤ by &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Date and time in JavaScript are represented with the Date object. We can’t create “only date” or “only time”: &lt;code&gt;Date&lt;/code&gt; objects always carry both.&lt;/li&gt;
&lt;li&gt;Months are counted from zero (yes, January is a zero month).&lt;/li&gt;
&lt;li&gt;Days of week in &lt;code&gt;getDay()&lt;/code&gt; are also counted from zero (that’s Sunday).&lt;/li&gt;
&lt;li&gt;Dates can be subtracted, giving their difference in milliseconds. That’s because a &lt;code&gt;Date&lt;/code&gt; becomes the timestamp when converted to a number.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Date.now()&lt;/code&gt; to get the current timestamp fast.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;References&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.toptal.com/software/definitive-guide-to-datetime-manipulation"&gt;https://www.toptal.com/software/definitive-guide-to-datetime-manipulation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.utctime.net/"&gt;https://www.utctime.net/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-time-values-and-time-range"&gt;https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-time-values-and-time-range&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.vroapi.com/Class/Intrinsics/1.0.0/Date"&gt;https://www.vroapi.com/Class/Intrinsics/1.0.0/Date&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>article</category>
      <category>tutorial</category>
      <category>datetime</category>
      <category>detailed</category>
    </item>
    <item>
      <title>List of available Node.js modules in vRO</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Tue, 15 Mar 2022 09:49:55 +0000</pubDate>
      <link>https://dev.to/imtrinity94/list-of-available-nodejs-modules-in-vro-412k</link>
      <guid>https://dev.to/imtrinity94/list-of-available-nodejs-modules-in-vro-412k</guid>
      <description>&lt;p&gt;Here is the list of node.js modules that comes preinstalled in vRO 8.3 when you select in &lt;strong&gt;Node.js 12&lt;/strong&gt; in Runtime.&lt;/p&gt;

&lt;p&gt;| &lt;strong&gt;&lt;em&gt;Module&lt;/em&gt;&lt;/strong&gt; | &lt;strong&gt;&lt;em&gt;Version&lt;/em&gt;&lt;/strong&gt; |&lt;br&gt;
| node | 12.18.3 |&lt;br&gt;
| v8 | 7.8.279.23-node.39 |&lt;br&gt;
| uv | 1.38.0 |&lt;br&gt;
| zlib | 1.2.11 |&lt;br&gt;
| brotli | 1.0.7 |&lt;br&gt;
| ares | 1.16.0 |&lt;br&gt;
| modules | 72 |&lt;br&gt;
| nghttp2 | 1.41.0 |&lt;br&gt;
| napi | 6 |&lt;br&gt;
| llhttp | 2.0.4 |&lt;br&gt;
| http_parser | 2.9.3 |&lt;br&gt;
| openssl | 1.1.1g |&lt;br&gt;
| cldr | 37.0 |&lt;br&gt;
| icu | 67.1 |&lt;br&gt;
| tz | 2019c |&lt;br&gt;
| unicode | 13.0 |&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Reference Script&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In Node.js, the &lt;code&gt;process.versions&lt;/code&gt; property is an inbuilt application programming interface of the process module which is used to get the versions of node.js modules and it’s dependencies. The &lt;code&gt;process.versions&lt;/code&gt; property returns an object listing the version strings of Node.js and its dependencies.&lt;/p&gt;

&lt;p&gt;.gist table { margin-bottom: 0; }&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span&amp;gt;
  This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
  &amp;lt;a href="https://github.co/hiddenchars" target="_blank"&amp;gt;Learn more about bidirectional Unicode characters&amp;lt;/a&amp;gt;
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
 &lt;a href="%7B%7B%20revealButtonHref%20%7D%7D"&gt; Show hidden characters

&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;span&gt;&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
&lt;br&gt;
&lt;/span&gt;

&lt;p&gt;| | exports.handler = (context, inputs, callback) =&amp;gt; { |&lt;br&gt;
| | const process = require('process'); |&lt;br&gt;
| | var no_versions = 0; |&lt;br&gt;
| | |&lt;br&gt;
| | var versions = process.versions; |&lt;br&gt;
| | console.log("|Module|Version|"); |&lt;br&gt;
| | console.log("|——|——-|"); |&lt;br&gt;
| | for (var key in versions) { |&lt;br&gt;
| | // Printing key and its versions |&lt;br&gt;
| | console.log("|"+key + "|" + versions[key]+"|"); |&lt;br&gt;
| | no_versions++; |&lt;br&gt;
| | } |&lt;br&gt;
| | console.log("Total no of values available = " + no_versions); |&lt;br&gt;
| | callback(undefined, { |&lt;br&gt;
| | status: "done" |&lt;br&gt;
| | }); |&lt;br&gt;
| | } |&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/imtrinity94/2aaec6958f00a375492a887fca65a6d8/raw/24821acee2adf959dd3b881182b803e198cbee17/vRO_nodejs_getAllModules.js"&gt;view raw&lt;/a&gt;&lt;a href="https://gist.github.com/imtrinity94/2aaec6958f00a375492a887fca65a6d8#file-vro_nodejs_getallmodules-js"&gt;vRO_nodejs_getAllModules.js&lt;/a&gt; hosted with ❤ by &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5ZBIULgv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-46.png%3Fw%3D923" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5ZBIULgv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-46.png%3Fw%3D923" alt="" width="880" height="840"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Let me know if you have an even better way to get the list of modules from vRO. See you.&lt;/p&gt;

</description>
      <category>article</category>
      <category>node</category>
      <category>polyglot</category>
      <category>scripting</category>
    </item>
    <item>
      <title>Quickly remove Clutter from vRO Logs</title>
      <dc:creator>Mayank Goyal</dc:creator>
      <pubDate>Mon, 14 Mar 2022 08:04:24 +0000</pubDate>
      <link>https://dev.to/imtrinity94/quickly-remove-clutter-from-vro-logs-4c5c</link>
      <guid>https://dev.to/imtrinity94/quickly-remove-clutter-from-vro-logs-4c5c</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Scenario&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;vRO provides great bit of logs out-of-the-box, but the problem is, it’s not aesthetically pleasing. Frankly, these long trials of data and time &lt;code&gt;[2022-03-14 02:33:03.144 -04:00INFO]&lt;/code&gt; annoys me a lot. So, just like me, If you don’t want that annoyance or you want to show these logs to someone in most tidiest way, or maybe you want to preserve an action/execution, then probably you are at the right place. Let’s see how I do it.&lt;/p&gt;

&lt;p&gt;I think the simplest way would be to find a Regex that removes it all in one go.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Solution&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;After execution of a workflow or action, copy the logs and open &lt;strong&gt;Notepad++&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;CTRL + H&lt;/strong&gt;. It will open &lt;strong&gt;&lt;em&gt;Replace&lt;/em&gt;&lt;/strong&gt; Tab.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B-Bj5SLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-44.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B-Bj5SLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-44.png%3Fw%3D1024" alt="" width="880" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;strong&gt;Find what&lt;/strong&gt; field copy the below mentioned RegEx and In &lt;strong&gt;Search Mode&lt;/strong&gt; , enable &lt;strong&gt;&lt;em&gt;Regular Expression&lt;/em&gt;&lt;/strong&gt; and tick &lt;strong&gt;Wrap around&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9i8GIhZW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-45.png%3Fw%3D246" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9i8GIhZW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cloudblogger2021.files.wordpress.com/2022/03/image-45.png%3Fw%3D246" alt="" width="246" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;for workflows&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.+?(?=:)+.+?(?=:)+.+?(?=:)+:(00|30)+(INFO|WARNING|DEBUG|ERROR)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  OR
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;for actions&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.+?(?=:)+.+?(?=:)+.+?(?=:)+:(00|30)+(INFO|WARNING|DEBUG|ERROR)+([^)]+)\)+( +?|\t)(?=(([^"]*"){2})*[^"]*$)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Replace All&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Try yourself at Regexr.com&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;for Workflows: &lt;a href="http://regexr.com/6haum"&gt;regexr.com/6haum&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;for Actions: &lt;a href="http://regexr.com/6hauv"&gt;regexr.com/6hauv&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>log</category>
      <category>notepad</category>
      <category>vro</category>
    </item>
  </channel>
</rss>
