Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help with Array

Abhijit Das7
Tera Expert

Hi Everyone,

 

I have an array from which I want to retrieve data and paste in work notes.

 

Array :  [07:20:28 - 07:22:30] Host - Ron,
[07:21:32 - 07:21:39] Guest - Guest 1,
[07:22:00 - 07:22:05] Guest - Guest 2,
[07:22:26 - 07:22:30] Guest - Guest 3

 

I want output like this:

Ron joined at 07:20:28 and left at 07:22:30

Guest 1 Joined at 07:21:32 and left at 07:21:39

Guest 2 joined at 07:22:00 and left at 07:22:05

Guest 3 joined at 07:22:26 and left at 07:22:30

and so on to Guest N.....

 

How can I retrieve data from this array. Please guide me in this.

 

Thanks in advance

1 ACCEPTED SOLUTION

Shubham_Jain
Mega Sage
Mega Sage

@Abhijit Das7 

 

var ParseArray = Class.create();
ParseArray.prototype = {
    initialize: function() {},

    getFormattedWorkNotes: function() {
        var data = [
            "[07:20:28 - 07:22:30] Host - Ron",
            "[07:21:32 - 07:21:39] Guest - Guest 1",
            "[07:22:00 - 07:22:05] Guest - Guest 2",
            "[07:22:26 - 07:22:30] Guest - Guest 3"
        ];
        
        var result = [];
        
        for (var i = 0; i < data.length; i++) {
            var entry = data[i].replace(/\[|\]/g, ''); // Remove brackets
            var parts = entry.split("] "); 
            var timeRange = parts[0];
            var personInfo = parts[1];

            var timeSplit = timeRange.split(" - ");
            var startTime = timeSplit[0];
            var endTime = timeSplit[1];

            var personSplit = personInfo.split(" - ");
            var role = personSplit[0];
            var name = personSplit[1];

            result.push(name + " joined at " + startTime + " and left at " + endTime);
        }

        return result.join("\n");
    },

    type: 'ParseArray'
};

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain


View solution in original post

1 REPLY 1

Shubham_Jain
Mega Sage
Mega Sage

@Abhijit Das7 

 

var ParseArray = Class.create();
ParseArray.prototype = {
    initialize: function() {},

    getFormattedWorkNotes: function() {
        var data = [
            "[07:20:28 - 07:22:30] Host - Ron",
            "[07:21:32 - 07:21:39] Guest - Guest 1",
            "[07:22:00 - 07:22:05] Guest - Guest 2",
            "[07:22:26 - 07:22:30] Guest - Guest 3"
        ];
        
        var result = [];
        
        for (var i = 0; i < data.length; i++) {
            var entry = data[i].replace(/\[|\]/g, ''); // Remove brackets
            var parts = entry.split("] "); 
            var timeRange = parts[0];
            var personInfo = parts[1];

            var timeSplit = timeRange.split(" - ");
            var startTime = timeSplit[0];
            var endTime = timeSplit[1];

            var personSplit = personInfo.split(" - ");
            var role = personSplit[0];
            var name = personSplit[1];

            result.push(name + " joined at " + startTime + " and left at " + endTime);
        }

        return result.join("\n");
    },

    type: 'ParseArray'
};

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain