"Posting CSV or Excel Files Directly to an Import Set": how to set charset?

sanoajul
Kilo Contributor

Hi all,

I'm facing an issue while posting CSV directly to an Import set setting charset for special character handling. It is working fine if the CSV does not contain any special character. I've gone through the URL (http://wiki.servicenow.com/index.php?title=Importing_Data_Using_Import_Sets#Posting_CSV_or_Excel_Fil...) for posting CSV directly to an Import set. Special character handling is working if I do it manually by Loading to a newly created Data Source where i set the Property field value as "charset=utf-8". This is mentioned in URL (http://wiki.servicenow.com/index.php?title=Data_Sources#Encoding). I need to know how to set the character-set so that it handles the special chracter after direct CSV file posting to Import Set. Below java code I have used.

String url = "https://dev.service-now.com/sys_import.do?sysparm_import_set_tablename=table_name&sysparm_transform_...;

PostMethod post = new PostMethod(url);
try {

HttpClient httpclient = new HttpClient();

Credentials defaultcreds = new UsernamePasswordCredentials(usrName , usrPwd);

// Prepare HTTP post
httpclient.getState().setCredentials(AuthScope.ANY, defaultcreds);

File targetFile = new File(transferFile);
FilePart filePart = new FilePart(targetFile.getName(), targetFile,   "application/octet-stream", "utf-8");
//filePart.setCharSet("utf-8");

Part[] parts = {filePart};

post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

int result = httpclient.executeMethod(post);

}

Thanks,

San

2 REPLIES 2

sanoajul
Kilo Contributor

Hi Guys,


I found a work around for this requirement. Condition is that the csv file name has to be same always. By default SN create data source with the file's name + (Uploaded) and continue using that same DS as long as the file name is same. So if we change the Properties filed value for that DS then it would work as i expected.



Thanks,


Sanoajul.


Hi,



I created a before insert business rule on Data source table since my filename will change every week. This rule will set properties to "charset=utf-8", whenever a new data source is created. This will work only if a certain part of filename remains constant.



Thanks,


Vikas.