Alter the data in the csv file that will be sent to the MIDServer using the Post-export script

Houssam
Tera Contributor

My API for the week : GlideTextReader !

 

Hi everyone, hope you are doing well.

 

I want to share with you a use case that I have encountered, which that the client want to sent a csv file to the midserver but wants to apport some data modification on that file using the Post-export script. basically he wanted to alternate two names of columns in the csv header.

 

Thought at first about using the database view, but unfortunately that will work only in case we were sending labels in the Headers of the csv file instead of the technical names.

 

So before I go in deep of what I did in terms of code, let me put here the blueprint that I have followed:

  1. Allow the first csv to get exported
  2. then in post export script i would do the following:
    1. I will get the content of the csv file by fetching the record from "sys_attachment" table
    2. Do the modification that I want and store in a string variable that will create my new csv file
    3. Replace the old csv file with the new one (*the attachment will be on the MidServer Attachement record (table is: ecc_agent_attachment))
    4. Then lastly, i will create a record on ecc_queue table with agent the midserver that I want ,  topic "StreamPipeline" , queue will be "output" , the state will be "ready" and lastly the Payload that will indicate the sys_id of the new attachment and the sys_id of the MID Server Attachment record where the attachment is

For reading the csv i used this code:

 

Houssam_4-1695299405164.png

 

 



This code has come in very handy since at first I was using getBytes() methode which works only for files less than 5 mb, but this new code that uses streams of data I used it for a file with 12 mb. and it worked fine , the only thing that you will need to pay attention to afterwards is the string variable that you will use to create the csv file where you would want to store the data, keep in mind that "String object limit of 33554432 bytes" so you may want to do it in chunks.

 

 

So after doing the modifications that i want I created my csv file:

 

Houssam_5-1695299444165.png

 

 

 


Then the last step is to create the ECC Queue record:

 

Houssam_6-1695299479743.png

 

 


 for the xml payload, it is as the following:

 

Houssam_7-1695299515980.png

 

 

 

1 REPLY 1

Houssam
Tera Contributor

Hello , for the limit of the string variable it can be altered by adding two properties:

 

glide.size.aware.max_size.org.mozilla.javascript.NativeString  -> 83886080 
glide.size.aware.max_size.java.lang.String   - >  83886080


Reference to the community post:
https://www.servicenow.com/community/now-platform-forum/attachment-size-limit-for-outbound-soap-mess...