Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Import a file to Servicenow from MID Server

Sathwik1
Tera Guru

I need to import a csv file from MID Server daily... Daily once the 3rd party will place a csv file in the MID Server...when ever they place I need to place that file in our MID Server...

Can anyone help me with this?  I referred previous community questions but I didn't get complete clarity...so please help me to understand clearly

1 ACCEPTED SOLUTION

@Sathwik 

Please find responses below

Question 1: Regarding First Script [Background Script ]

Should I run this in our instance is enough ? (or) should I login to Server in which MID Server is located and there I need to login to my developer instance and run?

- you should run this from your instance which is configured with the mid server

Question 2 : Regarding Business rule..

By this business rule..where my CSV file will get stored? It needs to attach to a import table in our instance

- you can attach it to the data source which you require to be transformed

- remember you need to trigger the transform as well once file gets attached to data source

Question 3 : This Process needs to run daily at certain time..

- create a schedule job which runs daily and uses the script shared above

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

18 REPLIES 18

@Sathwik 

Thanks for the update..

Please close the thread by marking appropriate response as correct so that it benefit future readers

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Sathwik 

Thanks for the update.

If my response helped please close the thread by marking my response as correct so that it benefit future readers

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Sathwik1
Tera Guru
@Kieran Anson  @Muhammad 

RobertM2
Giga Contributor

Hi Ankur,

Thanks for your response to this post. I think I have what you suggested in my version of this however this is not quite working for me (yet) and I am getting an error. I am trying to do this from a scoped app but global doesn't seem to work for me either.  Here is what I have done.

1. I uploaded a file to the mid server named "Positions.csv" under a subfolder called "import"

2. I created a scheduled script execution with the following code:

	var probe = SncProbe.get("Command");
	probe.setName("cd /SNow MidServer Info/agent/import && cat Positions.csv | base64");
	probe.create("DVMidServer"); // give mid server name here which is up and running

3. I created a business rule (tried this with both scoped and global) with the following parameters:

    Condition: Queue is input AND State is ready

    Script:  I changed the name to "Positions.csv" and the source to point to the data source sys_id. My intention was to attach the file to the data source so that the corresponding transform would run.

		var base64encodedData = ''; // after parsing this will contain the base64encoded data

		var s = new sn_ws.SOAPMessageV2('Attachment Creator', 'insert');
		s.setStringParameter('agent','AttachmentCreator');
		s.setStringParameter('name','Positions.csv:text/csv');
		s.setStringParameter('source','sys_data_source:d5f55855db26c410fc0075131f961928');
		s.setStringParameter('payload',base64encodedData);
		s.setStringParameter('topic','AttachmentCreator');
		var response = s.execute();

4. My data source is as follows:

find_real_file.png

 

My intent with this is to:

1. Check for a new file daily on the mid server

2. Import the file to the instance

3. Run the desired transform and import data to the target

 

I am getting this error message so far but I also feel like I may be missing something else.

 

SOAP Msg Outbound - SOAPMessageClient : Exception initializing Soap Message functionAttachment Creator.insert Message: Unable to find SOAP Message Record with Name: Attachment Creator: no thrown error

I am using the Orlando version at the moment.

 

I am not sure if I am supposed to create a new SOAP message (I have no idea how to do this correctly).  Here is a list of SOAP messages currently in the table:

find_real_file.png

 

 

Do you have any idea what I am doing wrong or what is missing? 

Is the file being brought into ServiceNow?

Did you check the ecc_queue record for that?

what comes in the BR on ecc_queue table?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader