Discussion:
Load variable with input data to send as one payload in a Webservice Call
(too old to reply)
TDIMakesMeCry
2018-09-14 18:50:37 UTC
Permalink
Hey all,

So the short of it is that I need to create an XML payload to send to a webservice, which is pretty easy. However, they need all data to be sent at once in one node of the XML in one upload (i.e., not 100 uploads of one, but one of 100 users). I can get it to be 100 uploads of one user but I can't get the one upload of 100 to work how I want it.

So far here is the XML creation:

var payload = ""
payload += work.UserName+","+work.FirstName+","+work.LastName+","+work.Email+","+work.phoneNumber+","+work.employeeNumber+","+work.title+","+work.errolename+","+work.business_unit_name+","+work.supervisorUID+","+work.currency+","+"50000,150000" + '\n'

var dataTransferRequestType = system.newEntry();
dataTransferRequestType.dataTransferRequestType = null;
dataTransferRequestType.dataTransferRequestType.login = null;
dataTransferRequestType.dataTransferRequestType.login.username = "[scrubbedUN]";
dataTransferRequestType.dataTransferRequestType.login.password = "[scrubbedPW]";
dataTransferRequestType.dataTransferRequestType.connector = "[scrubbedC]";
dataTransferRequestType.dataTransferRequestType.upload = null;
dataTransferRequestType.dataTransferRequestType.upload.setAttribute("dataFormat","csvCommaSeperated");
dataTransferRequestType.dataTransferRequestType.upload.setAttribute("dataEncoding","none");
dataTransferRequestType.dataTransferRequestType.upload.data = null;
dataTransferRequestType.dataTransferRequestType.upload.data.datatext = "<![CDATA[Username,First Name,Last Name,Email,Phone Number,Employee Id,Title,Role Name,Primary Business Unit,Primary Supervisor Username,Currency,[SA] CAD,[SA] USD" +'\n'+ payload +"]]>"
dataTransferRequestType.toXML()


and is sent as an output variable to the WS. Try as I might I just can't get it to load the variable and then actually do the toXML() part in either the webservice call or just in the log

any help you could give would be invaluable
j***@gmail.com
2018-09-19 04:18:02 UTC
Permalink
I am not sure exactly what the problem is.
Maybe you want to do a
var str = dataTransferRequestType.toXML()
to get the XML string?

Also, you might want to make datatext a CDATA section, maybe with code like this:

dataTransferRequestType.dataTransferRequestType.upload.data.datatext = work.createCDATASection(
"Username,First Name,Last Name,Email,Phone Number,Employee Id,Title,Role Name,Primary Business Unit,Primary Supervisor Username,Currency,[SA] CAD,[SA] USD" +'\n'+ payload);
m***@gmail.com
2018-09-19 13:11:34 UTC
Permalink
Oh I didn't know you could create a CDATA section like that, thanks!

I couldn't figure out quite how to articulate the problem very well. Basically the webservice can't accept 1 upload of each user that I'm pulling in, instead it needs one giant upload of all users and I can't for the life of me figure out how to get TDI to do that.

My test file has 12 users in it and I've been able to get 12 separate uploads of the users(like TDI is want to do), I've been able to get 1 user listed 12 times in an entry, but I can't get all 12 unique users to be loaded into one upload.
j***@gmail.com
2018-09-20 03:01:19 UTC
Permalink
From the example you provided, it seems that the upload should be in CSV format inside the XML body.
How about making two assemblylines, one that reads all the users and write them to a CSV file with the correct CSV format.
Then the other assemblyline could call the first assemblyLine to create the CSV file, and after that it could read the payload from the CSV file, construct the XML body from that, and send it to the webservice. Here is some code to read a file into a string.

var fileName = "users.csv";
var payload = system.arrayToString(java.nio.file.Files.readAllBytes(java.io.File(fileName).toPath()))

If you have SDI 7.2 FP4 or higher, the last line could be
var payload = system.arrayToString(system.readBytes(fileName))

It is also possible to combine everything into one AssemblyLine, e.g. using a loop, if you feel that is easier to understand.
m***@gmail.com
2018-09-20 12:30:34 UTC
Permalink
That works perfectly, oh my god. I can't tell you how much pain and strife you just saved me with this. You are literally the best ever. Thank you so much!
Eddie Hartman
2018-09-20 21:41:56 UTC
Permalink
Note that if it's too much data (many Mbyte) the you can use the Memory Store connector. Works like a File connector, excepts uses a memory buffer. Saves you having to coordinate file access in case of multiple threads/ALs.
Loading...