inboundCallDetails js
inboundCallDetails js
];
export default class InboundCallDetails extends NavigationMixin(LightningElement) {
get statusOptions() {
return [
{ label: '--None--', value: '' },
{ label: 'Completed', value: 'Completed' },
{ label: 'NRC Dispatcher', value: 'NRC Dispatcher' },
{ label: 'Ignore Alarm', value: 'Ignore Alarm' },
];
}
connectedCallback() {
this.initDetails();
window.addEventListener("message", (message) => {
console.log(message.origin);
console.log('LWC - Received message:', message.data);
this.coordinates = JSON.parse(JSON.stringify(message.data));
console.log('this.coordinates>>>117', this.coordinates);
});
}
initDetails() {
getDetails()
.then(result => {
this.vfRoot = result;
})
handleAccountChange(event) {
if (event.target.dataset.field == 'Name') {
this.isLoading = true;
this.customer = event.detail.selectedRecord;
this.callTypeDisabled = true;
this.issueTypeDisabled = true;
this.callType = '';
this.issueType = '';
this.callTypeOptions = [];
this.issueTypeOptions = [];
this.outboundDynamicFields = [];
this.inboundDynamicFields = [];
this.contactfields = [];
this.namefields = [];
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
handleCallTypeChange(event) {
this.callType = event.target.value;
this.issueTypeDisabled = true;
this.issueType = '';
this.issueTypeOptions = [];
this.outboundDynamicFields = [];
this.inboundDynamicFields = [];
this.contactfields = [];
this.namefields = [];
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
if (this.customer != '' && this.customer != undefined && this.callType !=
'' && this.callType != undefined) {
this.isLoading = true;
getIssueTypeOptions({ accountId: this.customer, callType: this.callType
})
.then(result => {
if (result != undefined && result.length > 1) {
this.isLoading = false;
this.issueTypeOptions = result;
this.issueTypeDisabled = false;
} else {
this.isLoading = false;
this.issueTypeDisabled = true;
this.issueType = '';
this.outboundDynamicFields = [];
this.inboundDynamicFields = [];
this.contactfields = [];
this.namefields = [];
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
const event = new ShowToastEvent({ title: '', message: 'No
issue type values found.', variant: 'info', });
this.dispatchEvent(event);
}
})
} else {
this.isLoading = false;
this.issueTypeDisabled = true;
this.issueType = '';
this.outboundDynamicFields = [];
this.inboundDynamicFields = [];
this.contactfields = [];
this.namefields = [];
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
}
}
handleIssueTypeChange(event) {
console.log('hasRun>>>');
this.isLoading = true;
this.issueType = event.target.value;
//get dynamic fields
if (this.customer != '' && this.customer != undefined && this.issueType !=
'' && this.issueType != undefined && this.callType != undefined && this.callType !=
'') {
getICM_Metadata({ accountId: this.customer, issueType: this.issueType,
callType: this.callType })
.then(result => {
console.log('resultIssueType>>>', result);
if (result != null && result != undefined) {
let nameFieldOUT = result.namefields;
if(this.hasValue){
let contactfields = result.contactfields;
for (i = 0; i < contactfields.length; i++ ) {
if (contactfields[i].fieldAPIName == 'Contact_1__c') {
contactfields[i].fieldValue = this.contactOne;
} else if (contactfields[i].fieldAPIName ==
'Contact_2__c') {
contactfields[i].fieldValue = this.contactTwo;
break;
}
}
}
if (result.outboundDynamicFields) {
this.outboundDynamicFields =
result.outboundDynamicFields;
} else {
this.outboundDynamicFields = [];
}
if (result.inboundDynamicFields) {
this.inboundDynamicFields =
result.inboundDynamicFields;
if (this.inboundDynamicFields[i].isText &&
this.inboundDynamicFields[i].fieldAPIName == 'Description') {
if (this.inboundDynamicFields[i].fieldValue
!= undefined || this.inboundDynamicFields[i].fieldValue != null ||
this.inboundDynamicFields[i].fieldValue != '') {
this.inboundDynamicFields[i].isDescription = true;
this.inboundDynamicFields[i].isText =
false;
}
}
}
console.log('afterexitfields',
this.inboundDynamicFields);
}
} else {
this.inboundDynamicFields = [];
}
if (result.contactfields) {
this.contactfields = result.contactfields;
if (this.contactfields.length == 2) {
this.hasBothContacts = true;
} else {
this.hasBothContacts = false;
}
} else {
this.contactfields = [];
}
if (result.namefields) {
this.namefields = result.namefields;
if (this.namefields.length == 2) {
this.hasBothName = true;
} else {
this.hasBothName = false;
}
} else {
this.namefields = [];
}
if (result.locationInfo) {
this.locationInfo = result.locationInfo;
this.coordinates.formatted_address =
this.locationInfo.fieldValue;
if (this.locationInfo.showField &&
this.coordinates.formatted_address) {
setTimeout(() => {
this.populateLocationAdd(this.coordinates.formatted_address);
}, 3000);
}
if (this.locationInfo.disableField) {
setTimeout(() => {
if (this.template.querySelector("iframe")) {
var vfWindow =
this.template.querySelector("iframe").contentWindow;
if (vfWindow) {
vfWindow.postMessage(true,
this.vfRoot);
}
}
}, 3000);
}
if (!this.locationInfo.showField) {
this.showMap = false;
}
} else {
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
}
this.isLoading = false;
} else {
this.outboundDynamicFields = [];
this.inboundDynamicFields = [];
this.contactfields = [];
this.namefields = [];
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
this.isLoading = false;
}
})
} else {
this.isLoading = false;
this.outboundDynamicFields = [];
this.inboundDynamicFields = [];
this.contactfields = [];
this.namefields = [];
this.coordinates = {
latitude: undefined,
longitude: undefined,
formatted_address: '',
street: '',
country: '',
region: '',
postal_code: '',
locality: ''
};
this.locationInfo = {
fieldValue: '',
showField: false,
disableField: false,
isRequiredField: false
};
}
handleNotesChange(event) {
this.notes = event.target.value;
}
loadCompanyLocations(event) {
this.isLoading = true;
console.log('Marker', this.coordinates);
console.log('Event Target Dataset Value', event.target.dataset.value ===
'ShowMap');
console.log('Event Target Dataset Value POI', event.target.dataset.value
=== 'POI');
console.log('coordinates.latitude', this.coordinates.latitude);
console.log('coordinates.longitude', this.coordinates.longitude);
showSCADAModel(event) {
this.enableinboundmodel = true;
this.dispatchEvent(new CustomEvent('showinboundmodel', {
detail: {
message: this.enableinboundmodel
}
}));
}
hideSCADAModel(event) {
this.enableinboundmodel = false;
this.dispatchEvent(new CustomEvent('showinboundmodel', {
detail: {
message: this.enableinboundmodel
}
}));
}
closeModal(event) {
this.showRecordDetails = false;
}
handleAssetLocationSelection(event) {
this.showRecordDetails = false;
if (this.assetLoc.formatted_address) {
const address = Array.isArray(this.assetLoc.formatted_address) ?
this.assetLoc.formatted_address : [this.assetLoc.formatted_address];
console.log('Sending address from LWC:', address);
this.coordinates.formatted_address = this.assetLoc.formatted_address;
this.coordinates.latitude = this.assetLoc.latitude;
this.coordinates.longitude = this.assetLoc.longitude;
this.coordinates.country = '';
this.coordinates.postal_code = '';
this.coordinates.region = '';
this.coordinates.street = '';
this.coordinates.locality = '';
}
}
// Extract and use the values from the selected rows directly
selectedRows.forEach(row => {
this.assetLoc.formatted_address = row.Address__c;
this.assetLoc.latitude = row.Location__Latitude__s;
this.assetLoc.longitude = row.Location__Longitude__s;
console.log('Address__c:', this.coordinates.formatted_address);
});
};
handleInputChange(event) {
var fieldName = event.target.dataset.name;
for (var i = 0; i < this.outboundDynamicFields.length; i++) {
if (this.outboundDynamicFields[i].fieldAPIName == fieldName) {
if (this.outboundDynamicFields[i].isCheckbox) {
this.outboundDynamicFields[i].fieldValue =
event.target.checked;
} else if (this.outboundDynamicFields[i].isLookup) {
this.outboundDynamicFields[i].fieldValue =
event.detail.recordId;
} else if (this.outboundDynamicFields[i].isMultiPicklist) {
this.outboundDynamicFields[i].multiPicklistValue =
event.target.value;
} else {
this.outboundDynamicFields[i].fieldValue = event.target.value;
}
}
}
}
handleInboundValuesChange(event) {
var fieldName = event.target.dataset.name;
for (var i = 0; i < this.inboundDynamicFields.length; i++) {
if (this.inboundDynamicFields[i].fieldAPIName == fieldName) {
if (this.inboundDynamicFields[i].isCheckbox) {
this.inboundDynamicFields[i].fieldValue = event.target.checked;
} else if (this.inboundDynamicFields[i].isLookup) {
this.inboundDynamicFields[i].fieldValue =
event.detail.recordId;
} else if (this.inboundDynamicFields[i].isMultiPicklist) {
this.inboundDynamicFields[i].multiPicklistValue =
event.target.value;
} else {
this.inboundDynamicFields[i].fieldValue = event.target.value;
}
}
}
}
handleContactValuesChange(event) {
var fieldName = event.target.dataset.name;
console.log('####', event.target.value);
if (fieldName == 'Contact_1__c') {
this.contactOne = event.target.value;
} else if (fieldName == 'Contact_2__c') {
this.contactTwo = event.target.value;
}
if (fieldName == 'First_Name__c') {
this.fName = event.target.value;
} else if (fieldName == 'Last_Name__c') {
this.lName = event.target.value;
}
console.log('fieldIndex>', fieldIndex);
for (var i = 0; i < this.namefields.length; i++) {
if (this.namefields[i].isMultiPicklist) {
this.namefields[i].multiPicklistValue = event.target.value;
} else {
this.namefields[fieldIndex].fieldValue = event.target.value;
//this.namefields[fieldName].fieldValue = event.target.value;
}
}
}
handleSearchChange(event) {
this.searchCriteria = event.target.value;
console.log('searchCriteria', this.searchCriteria);
record.Name.toLowerCase().includes(this.searchCriteria.toLowerCase()) ||
record.Address__c.toLowerCase().includes(this.searchCriteria.toLowerCase())
);
console.log('Filtered Data:', this.customerdata);
this.showRecordDetails = true;
} else {
console.log('No records found.');
}
})
.catch(error => {
this.error = error;
console.error('Error fetching company locations:', error);
});
}
handleSave(event) {
this.isLoading = true;
let inputFields = this.template.querySelectorAll('lightning-input');
inputFields.forEach(inputField => {
if (!inputField.checkValidity()) {
inputField.reportValidity();
}
});
let inputPicklistFields = this.template.querySelectorAll('lightning-
combobox');
inputPicklistFields.forEach(inputPicklistFields => {
if (!inputPicklistFields.checkValidity()) {
inputPicklistFields.reportValidity();
}
});
if (this.customer != undefined && this.customer != null && this.customer !=
'' &&
this.issueType != undefined && this.issueType != null && this.issueType
!= '' &&
this.callType != undefined && this.callType != null && this.callType !=
'' &&
(this.locationInfo.showField == false ||
this.locationInfo.isRequiredField == false || (this.locationInfo.showField &&
this.locationInfo.isRequiredField && this.coordinates != undefined &&
this.coordinates != null &&
(this.coordinates.formatted_address != undefined &&
this.coordinates.formatted_address != null && this.coordinates.formatted_address !=
'') ||
(this.coordinates.latitude != undefined &&
this.coordinates.longitude != undefined && this.coordinates.latitude != '' &&
this.coordinates.longitude != '') &&
this.coordinates.latitude != null && this.coordinates.longitude != null))) {
}
}
if (this.inboundDynamicFields) {
for (var i = 0; i < this.inboundDynamicFields.length; i++) {
if (this.inboundDynamicFields[i].showField &&
this.inboundDynamicFields[i].isRequiredField &&
(this.inboundDynamicFields[i].fieldValue == null ||
this.inboundDynamicFields[i].fieldValue == '' ||
this.inboundDynamicFields[i].fieldValue == undefined)) {
validRequiredInputs = false;
}
}
}
if (this.contactfields) {
for (var i = 0; i < this.contactfields.length; i++) {
if (this.contactfields[i].showField &&
this.contactfields[i].isRequiredField && (this.contactfields[i].fieldValue == null
|| this.contactfields[i].fieldValue == '' || this.contactfields[i].fieldValue ==
undefined)) {
validRequiredInputs = false;
}
}
}
if (this.namefields) {
for (var i = 0; i < this.namefields.length; i++) {
if (this.namefields[i].showField &&
this.namefields[i].isRequiredField && (this.namefields[i].fieldValue == null ||
this.namefields[i].fieldValue == '' || this.namefields[i].fieldValue == undefined))
{
validRequiredInputs = false;
}
}
}
if (validRequiredInputs == true) {
var inboundDetails = {
accountId: this.customer,
issueType: this.issueType,
callType: this.callType,
callerLastName: this.callerLastName,
callerFirstName: this.callerFirstName,
notes: this.notes
}
var dynamicFields = [];
if (this.outboundDynamicFields) {
for (var i = 0; i < this.outboundDynamicFields.length; i++) {
dynamicFields.push(this.outboundDynamicFields[i]);
}
}
if (this.inboundDynamicFields) {
for (var i = 0; i < this.inboundDynamicFields.length; i++) {
dynamicFields.push(this.inboundDynamicFields[i]);
}
}
if (this.contactfields) {
for (var i = 0; i < this.contactfields.length; i++) {
dynamicFields.push(this.contactfields[i]);
}
}
if (this.namefields) {
for (var i = 0; i < this.namefields.length; i++) {
dynamicFields.push(this.namefields[i]);
}
}
if (dynamicFields) {
for (var i = 0; i < dynamicFields.length; i++) {
if (dynamicFields[i].isMultiPicklist &&
dynamicFields[i].multiPicklistValue) {
dynamicFields[i].fieldValue =
Array.isArray(dynamicFields[i].multiPicklistValue) ?
dynamicFields[i].multiPicklistValue.join(';') :
dynamicFields[i].multiPicklistValue;
}
}
}
if (result.recordId) {
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: result.recordId,
actionName: 'view',
},
});
}
} else {
this.isLoading = false;
const event = new ShowToastEvent({ title: 'Error',
message: result.msg, variant: 'error', });
this.dispatchEvent(event);
}
})
} else {
this.isLoading = false;
const event = new ShowToastEvent({ title: 'Error', message: 'Please
enter the required fields', variant: 'warning', });
this.dispatchEvent(event);
}
} else {
this.isLoading = false;
const event = new ShowToastEvent({ title: 'Error', message: 'Please
enter the required fields', variant: 'warning', });
this.dispatchEvent(event);
}
}
populateLocationAdd(adress) {
const address = Array.isArray(adress) ? adress : [adress];
console.log('Sending address from LWC:', address);
if (this.template.querySelector("iframe")) {
var vfWindow = this.template.querySelector("iframe").contentWindow;
if (vfWindow) {
vfWindow.postMessage(address, this.vfRoot);
}
}
console.log('Posted message to VF:', address);
}