$(document).ready( function() { app.initialized() .then(function(_client) { var client = _client; client.events.on('app.activated', function() { let printwindow=function(){ var winPrint = window.open(); winPrint.document.write($('html').html()); setTimeout(function () { winPrint.document.close(); }, 500); winPrint.focus(); $(winPrint.window).on('load', function () { winPrint.print(); winPrint.close(); }); } function ticketdetails(){ client.iparams.get().then(function (iparam) { domain=iparam.domain; client.data.get("ticket").then(function(ticketdata){ console.log(ticketdata); let ticketid= ticketdata.ticket.id, subject=ticketdata.ticket.subject, description=ticketdata.ticket.description_text, ticketcreated=ticketdata.ticket.created_at, priority=ticketdata.ticket.priority, rmatype=ticketdata.ticket.custom_fields.cf_rma_type768901, callsign=ticketdata.ticket.custom_fields.cf_call_sign_1150894, shippingaddress=ticketdata.ticket.custom_fields.cf_shipping_address419237, // billingaddress=ticketdata.ticket.custom_fields.cf_billing_address128711, expeditedrepair=ticketdata.ticket.custom_fields.cf_priority_queue_placement, relatedsoorinvoice=ticketdata.ticket.custom_fields.cf_related_so_or_invoice195918, partampserialnumbers=ticketdata.ticket.custom_fields.cf_part_no_description_serial_numbers_freq_etc; let date=ticketcreated.split("T") let array=['Low','Medium','High','Urgent'] if(priority==1){ priority=array[0]; } if(priority==2){ priority=array[1]; } if(priority==3){ priority=array[2]; } if(priority==4){ priority=array[3]; } console.log(priority); console.log(date); console.log(rmatype); console.log(expeditedrepair); // console.log(billingaddress); $("#ticket_id").html(ticketid); $("#rma_date").html(date[0]); $("#subject").html(subject); $("#description").html(description); $("#ticket_priority").html(priority); $("#rma_type").html(rmatype); $("#expedited").html(expeditedrepair); $("#related_invoice").html(relatedsoorinvoice) $("#call_sign").html(callsign); $("#serial_number").html(partampserialnumbers) $("#ship").html(shippingaddress); var headers = { "Authorization": "Basic <%= encode(iparam.apiKey) %>", "Content-Type": "application/json; charset=utf-8" }; var options = { headers: headers}; let url=`https://${domain}/api/v2/tickets/${ticketid}?include=requester` client.request.get(url, options) .then( function(getdata) { let obj= JSON.parse(getdata.response); let reqname=obj.requester.name; console.log(reqname); $("#requester").html(reqname); }); }); }); } function companydetails(){ client.data.get("company").then ( function(data) { let companyid=data.company.id; console.log(companyid); let billingaddress=(data.company.custom_fields.billing_address); console.log("billing result",billingaddress); var headers = { "Authorization": "Basic <%= encode(iparam.apiKey) %>", "Content-Type": "application/json; charset=utf-8" }; var options = { headers: headers}; let url=`https://${domain}/api/v2/companies/${companyid}` client.request.get(url,options).then(function(companydata){ console.log(companydata); let companydetails=JSON.parse(companydata.response); console.log(companydetails); let companyname=companydetails.name console.log("company_name",companyname); $("#comp_name").html(companyname); $("#comp_address").html(billingaddress); }); }); } Promise.all([ticketdetails(),companydetails()]).then(function () { client.interface.trigger("showNotify", { type: "success", title: "Print app", message: "Loading ..." }); setTimeout(function(){ printwindow(); },3000) }).catch(function(error){ console.log(error); }) }); }); });