Need to create multiple requests from excel attached

Pallavi65
Tera Contributor

Hi all,

 

There will be an excel file attached to an incident via Inbound email action. That excel consists of 3 columns

Server, Application and Group.

For example, there are 5 rows in that excel and there are two applications that are in common.

1. Server1, App1, Database group

2. Server2, App1, Database group

3. Server3, App2, Database Group

4. Server4, App3, Infra Group

5. Server5, App4, Logistics Group

 

So, here the first two records have same application name. So, from this excel I want to create 4 requests automatically. In the first request, the short description should have Application name and the description should have the two servers. And the separate requests for other rows of the excel and they should be assigned to the assignment group mentioned in the third column.

So, in one word, for every one application one request should be created.

 

Please tell me how can I get this?

 

 

Thanks in advance.

 

 

Regards,

Pallavi

 

 

17 REPLIES 17

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
Please try to implement the logic as per below code-

 

    var obj=[
        {
            "Servername": "Server1",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server2",
            "Application": "Reebok",
            "AssignmentGroup": "Infra group"
        },
        {
            "Servername": "Server3",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server4",
            "Application": "Habilis",
            "AssignmentGroup": "Database"
        },
        {
            "Servername": "Server5",
            "Application": "Pitagor",
            "AssignmentGroup": "Database"
        },
        {
            "Servername": "Server6",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server7",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server8",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server9",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server10",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        },
        {
            "Servername": "Server11",
            "Application": "Atlas",
            "AssignmentGroup": "Active Directory"
        }
    ];

    var app=[];
    for(var i in obj)
    {
    app.push(obj[i].Application)
    }

    var au=new ArrayUtil();
    var app1=au.unique(app);
    
    var newObj=[];
    for(var j in app1)
    {
        var ser=[];
    for(var i in obj)
    
    {
        if(obj[i].Application==app1[j])
    ser.push(obj[i].Servername)
    }
newObj.push({"app":app1[j],"servers":ser})
    }
    gs.info("Original Request: "+obj.length)
    gs.info(JSON.stringify(newObj))
      gs.info("New Request: "+newObj.length)

 

 

SaurabhG_0-1668691339067.png

 





Thanks and Regards,

Saurabh Gupta

Hi Saurabh,

 

Thanks for your reply. But where should I write this logic? It would be helpful if you can provide me steps.

Also, one more thing is, an email will be sent to Service-now with an Excel attachment. So, what if there are 50 rows in that excel? We can give like that in an array for all rows, right?

 

Please guide me

 

 

Regards,

Pallavi

Hi Pallavi,

If you are using import set method through the attachment, I think this logic can be placed inside onComplete script.

First you should tell me the logic about how data is coming to ServiceNow and how in the current system you are raising a request. is it a catalog or record producer?


Thanks and Regards,

Saurabh Gupta

No Saurabh,

 

The excel file will be coming and creating an Incident via Inbound email. So, from that incident we will take that excel manually and run a data source. This is also fine for us.

 

Please help. 

 

 

Regards,

Pallavi

Hi Saurabh,

 

Can you please help me to my query? We will get the Excel attached to an Incident and from that We will use Data source and upload that excel and run it. 

 

 

Regards,

Pallavi