In my previous blogs, I have explained how to authenticate the SharePoint with JITBIT helpdesk system and create helpdesk tickets in JITBIT.
Please follow the below links to authentication and Creating tickets in JITIT helpdesk system
Now, we are going to implement file upload feature while creating ticket from SharePoint to JITBIT system content, like Images, PDF, Documents, Spreadsheets.
Create a Ticket With File Attachments
POST - https://helpdeskurl/helpdesk/api/ticket
It helps to create a ticket with attachment.
- function createTicket() {
- // Pass the necessary variables var catID, ticketBody, ticketSubject, pId,
- // Get the value from the HTML Elements
- catID = $('#picktech').val();
- ticketBody = $('#txtbody').val();
- ticketSubject = $('#txtsub').val();
- pId = $('#picktech2').val(); // Append the form data to POST into JITBIT system
- var form = new FormData();
- form.append("categoryId", catID); // Pass category ID from the dropdown
- form.append("body", ticketBody); // Pass Ticket Body from input element
- form.append("subject", ticketSubject); // Pass the subject from input element
- form.append("priorityId", pId); // Pass priorityId from input element
- form.append("userId", unameid); // Pass the userId of the current user what we already generated and stored globally
- //Upload multiple file attachments into form data
- $.each($('#file')[0].files, function(i, file) {
- form.append('file' + i, file);
- });
- // Now the ajax request calls
- $.ajax({
- "async": true,
- "crossDomain": true,
- "url": "https://vinodh.jitbit.com/helpdesk/api/ticket",
- "method": "POST",
- "headers": {
- "authorization": auth
- },
- "processData": false,
- "contentType": false,
- "mimeType": "multipart/form-data",
- "data": form, // Form data we appended before
- success: function(response) {
- swal({
- title: "Awesome!",
- text: "Ticket: " + response + " has been created successfully", // Am using SWAL sweet alert for success
- type: "success"
- }); // Clear the elements after successful submission
- $('#picktech').val("");
- $('#txtbody').val("");
- $('#txtsub').val("");
- $('#picktech2').val("");
- $('#file').val("");
- },
- error: function(error) {
- //Capture the error of API Call
- swal({
- title: "Oops!",
- text: "Something Went wrong",
- type: "error"
- });
- }
- });
- }
HTML


Join the conversation! Your thoughts help the community grow.