Hey Guys,
I have a widget published to our Freshdesk that uses iparams and OAUTH to retrieve data from our backend services and display that data in dropdowns to help with ticket completion. The app works fine locally but when published to production, the app stops working and I need to clear my cache to get it working again.
Here is my app.js file within the scripts folder, I’m using the latest FDK version too:
var client, getDetailsEl, caseIdEl, helixAdminTasksEl;
const onAppDeactiveHandler = () => {
return;
};
init();
const showModal = () => {
if (!caseIdEl.value) {
displayStatus(
"warning",
"Please enter the Helix Case Id located above the Get Details button"
);
return;
} else {
client.interface.trigger("showModal", {
title: "Helix Admin Tasks",
template: "modal.html",
data: { CaseId: caseIdEl.value },
});
}
};
const getAccessToken = async () => {
try {
const res = await client.request.invokeTemplate("getAccessToken", {
context: {},
body: "grant_type=client_credentials&scope=7c3e2740-2ad7-4210-a442-e4c909452c1d%2F.default&client_id=7c3e2740-2ad7-4210-a442-e4c909452c1d&client_secret=<%= iparam.client_secret %>",
});
console.log(JSON.parse(res.response).access_token);
return JSON.parse(res.response).access_token;
} catch (e) {
console.log(e);
}
};
const getClinicalCase = async (access_token) => {
try {
let res = await client.request.invokeTemplate("getClinicalCase", {
context: {
caseId: caseIdEl.value,
access_token: access_token,
},
});
return JSON.parse(res.response);
} catch (e) {
console.log(e);
}
};
const getClient = async (access_token, clientId) => {
try {
let res = await client.request.invokeTemplate("getClient", {
context: {
clientId: clientId,
access_token: access_token,
},
});
return JSON.parse(res.response);
} catch (e) {
console.log(e);
}
};
const getAnimal = async (access_token, animalId) => {
try {
let res = await client.request.invokeTemplate("getAnimal", {
context: {
animalId: animalId,
access_token: access_token,
},
});
return JSON.parse(res.response);
} catch (e) {
console.log(e);
}
};
const getClinic = async (access_token, clinicId) => {
try {
let res = await client.request.invokeTemplate("getClinic", {
context: {
clinicId: clinicId,
access_token: access_token,
},
});
return JSON.parse(res.response);
} catch (e) {
console.log(e);
}
};
const getDetails = async () => {
console.log("Get details fired");
try {
const access_token = await getAccessToken();
const resCase = await getClinicalCase(access_token);
const {
clientId,
animalId,
clinicId,
caseId,
memberPracticeName,
insuranceCompanyName,
dischargeStatus,
caseDate,
} = resCase;
console.log(resCase);
// Get Client
const resClient = await getClient(access_token, clientId);
const { salutationName, forename, surname } = resClient;
console.log(resClient);
// Get Animal
const resAnimal = await getAnimal(access_token, animalId);
const { animalName, insuranceCompany, insurancePolicyNo, species } =
resAnimal;
console.log(resAnimal);
// Get Clinic
const resClinic = await getClinic(access_token, clinicId);
const { clinicName, districtName } = resClinic;
console.log(resClinic);
// Display confirmation
client.interface.trigger("showNotify", {
type: "success",
message: "Case details retrieved from Helix",
});
updateFields({
ClientNameWithTitle: salutationName + " " + forename + " " + surname,
AnimalName: animalName,
ClinicName: clinicName,
DistrictName: districtName,
InsuranceCompany: insuranceCompany,
InsurancePolicyNo: insurancePolicyNo,
CaseId: caseId,
Species: species,
MemberPracticeName: memberPracticeName,
InsuranceCompanyName: insuranceCompanyName,
DischargeStatus: dischargeStatus,
CaseDate: caseDate,
});
addPrivateNote();
} catch (e) {
console.error(e);
client.interface.trigger("showNotify", {
type: "warning",
message: "Error fetching case details from Helix",
});
}
};
const updateFields = (data) => {
client.interface.trigger("setValue", {
id: "cf_helix_case_no",
value: data.CaseId,
});
client.interface.trigger("setValue", {
id: "cf_clinic_location",
value: data.ClinicName,
});
client.interface.trigger("setValue", {
id: "cf_client_name",
value: data.ClientNameWithTitle,
});
client.interface.trigger("setValue", {
id: "cf_pet_name",
value: data.AnimalName,
});
client.interface.trigger("setValue", {
id: "cf_pet_breed",
value: data.Species,
});
client.interface.trigger("setValue", {
id: "cf_practice",
value: data.MemberPracticeName,
});
client.interface.trigger("setValue", {
id: "cf_district",
value: data.DistrictName,
});
client.interface.trigger("setValue", {
id: "cf_ins_policy_number",
value: data.InsurancePolicyNo,
});
client.interface.trigger("setValue", {
id: "cf_hlx_insurance_company",
value: data.InsuranceCompanyName,
});
client.interface.trigger("setValue", {
id: "cf_incident_date",
value: new Date(data.CaseDate),
});
};
const addPrivateNote = () => {
const note =
"<h3>Helix documentation</h3>" +
"<ul>" +
"<li><a target='_blank' href='https://helix.vets-now.com/PrintWindow.aspx?rn=ClinicalHistory&caseid=" +
caseIdEl.value +
"'>Clinical History</a></li>" +
"<li><a target='_blank' href='https://helix.vets-now.com/PrintWindow.aspx?rn=CaseInvoiceSummary&caseid=" +
caseIdEl.value +
"'>Case statement</a></li>" +
"<li><a target='_blank' href='https://helix.vets-now.com/CaseDetail.aspx?id=" +
caseIdEl.value +
"'>Helix Case Details Window</a></li>" +
"</ul>";
client.interface
.trigger("click", {
id: "note",
text: note,
isPublic: false,
})
.then(function (data) {
console.log("Note populated:", data);
})
.catch(function (error) {
console.log(error);
});
};
const onAppActiveHandler = () => {
getDetailsEl = document.querySelector("#helix-request-get");
getDetailsEl.addEventListener("click", getDetails);
caseIdEl = document.getElementById("inpCaseId");
helixAdminTasksEl = document.querySelector("#helix-admin-tasks");
helixAdminTasksEl.addEventListener("click", showModal);
};
async function init() {
client = await app.initialized();
console.log("Client: " + client);
client.events.on("app.activated", onAppActiveHandler);
client.events.on("app.deactivated", onAppDeactiveHandler);
}