Hi Brian, Jerome
Thank you for your assistance, I think the problem is that we are approaching the requirement from a JavaScript perspective doing Ajax posts to the CA Service as opposed to the sample mechanism which uses Java, is this still possible?
Below is the code we are attempting to pass, we have tried to make it match the Java sample as closely as possible
1st Snippet: the call from the page to the posting function. (payload)
var payload = "<cr>";
if( $('#summary').val() != "" )
payload+= "<summary>"+$('#summary').val()+"</summary>";
if( $('#description').val() != "" )
payload+= "<description>"+$('#description').val()+"</description>";
payload+= "<status REL_ATTR='"+$('#status').val()+"'></status>";
if ( getAutoSuggestHValue(LABEL_ASSIGNEE) != "" )
payload += "<assignee id=\"" + getAutoSuggestHValue(LABEL_ASSIGNEE) + "\"></assignee>";
else // set assignee to null anyway
payload += "<assignee id=\"U'00000000000000000000000000000000'\"></assignee>";
if ( getAutoSuggestHValue(LABEL_CUSTOMER) != "" )
payload+= "<customer id=\"" + getAutoSuggestHValue(LABEL_CUSTOMER) + "\"></customer>";
if( ! $('#priority').is(':hidden') )
payload+= "<priority REL_ATTR='"+$('#priority').val()+"'></priority>"
//payload+= "<impact REL_ATTR='"+$('#impact').val()+"'></impact>";
//payload+= "<urgency REL_ATTR='"+$('#urgency').val()+"'></urgency>";
payload+= "<category REL_ATTR='"+$('#category').val()+"'></category>";
if ( getAutoSuggestHValue(LABEL_GROUP) != "" )
payload+= "<group id=\"" + getAutoSuggestHValue(LABEL_GROUP) + "\"></group>";
payload+= "<zBusinessUnitAffected REL_ATTR='"+$('#businessunitaffected').val()+"'></zBusinessUnitAffected>";
payload += "<type REL_ATTR='R'></type>";
//payload += "<attmnt>data:image/jpeg;base64," + localStorage.getItem("Photo") + "</attmnt>";
payload += "</cr>";
// Send POST request
var queryURL = restUrl + "/cr";
var fileInput = $('#attachment')[0];
var fileData = fileInput.files[0];
makeAjaxPostCallFileUpload(queryURL, accessKey, payload, fileData, "xml", processSaveResponse);
2nd Snippet: the ajax post to the service with combined form data (multipart) using the octet stream for file and the xml for the payload... Payload saves perfectly File creates an empty file in the attachments folder ( which seems to be held onto as it can't be deleted), but we end up with a request 400 bad request without any error being logged OR returned in the JQXR object, even when the verbosity on the log is set to debug.
function makeAjaxPostCallFileUpload(query, accessKey, appData, fileData, format, successCB)
{
var xmlBlob = new Blob([appData], { type: 'application/' + format });
var formData = new FormData();
formData.append("cr", xmlBlob);
//var imageBlob = new Blob([e.srcElement.result], { type: 'application/octet-stream' });
var imageBlob = new Blob([fileData], { type: 'application/octet-stream' });
formData.append("file", imageBlob);
var repositoryId='1002'; // ServiceDesk repository
var queryWithParams = query + '?repositoryId=' + repositoryId + '&serverName=localhost&mimeType=text&description=test&fileName=CRTest2.jpg'; // just test something that could work, change this after we have uploaded a file.
$.ajax({
url: queryWithParams,
data: formData,
headers: {
"X-AccessKey": accessKey,
"Content-Type": "multipart/form-data"
},
//contentType: false,
processData: false,
type: "POST",
dataType: format,
cache: false,
success: successCB,
error: reportError,
complete: completeAjaxPost
});
}
Thank you for your assistance thus far.
Jacques