I have worked on LWC requirement where
- On Case record, I have customized a component, which is based on custom metadata for the UI display and multi picklist for the back end.
- As a case owner ONLY I CAN EDIT or selected a picklist, it will display the options based on picklist from the custom metadata(the same value will be in the multi picklist in the backend). 3)The issues I am having are how can I after saving the record a) refresh the page to display the checked boxes and b) disable the picklist chosen but not the options.
import { LightningElement, track,api } from 'lwc';
import checkOwnerId from '@salesforce/apex/checkCaseFieldsCaseOwner.checkCurrentUserIsRecordOwner';
import getCustumMetadata from '@salesforce/apex/checkCaseFieldsCaseOwner.getCustumMetadata';
import updateCasewithChosenvalues from'@salesforce/apex/checkCaseFieldsCaseOwner.updateCasewithChosenvalues';
export default class TodoMultipicklistCustom extends LightningElement {
@track options=[];
@api recordId;
@track checkboxesString;
connectedCallback(){
checkOwnerId({recordId: this.recordId})
.then(result => {
if(result){
this.disabled = false;
}
})
.catch(error => {
this.error = error;
});
}
get brokerOptions() {
return [
{ label: 'None', value: 'None'},
{ label: 'State Farm Principal Officer', value: 'State Farm Principal Officer' },
{ label: 'State Farm Licensed Team Member', value: 'State Farm Licensed Team Member' }
];
}
handleChange(event) {
this.value = event.detail.value;
this.options.length=0;
getCustumMetadata({Type : this.value })
.then(result => {
console.log(JSON.stringify(result));
let optionsObject;
//result.forEach(element => console.log(element));
result.forEach(element=>{
optionsObject = new Object();
optionsObject.label = element;
optionsObject.value = element;
console.log('+++++options*'+ JSON.stringify(optionsObject))
this.options.push(optionsObject);
console.log('***'+ JSON.stringify(this.options))
});
console.log(JSON.stringify(this.options));
})
.catch(error => {
this.error = error;
});
}
handleCheckboxgroup(event) {
let data;
data = event.target.value;
this.checkboxesString=data.split(',').join(':');
console.log('*****'+ this.checkboxesString);
}
updateCase(){
updateCasewithChosenvalues({
recordId: this.recordId,
ToDo_Typ: this.value,
optionsChecked: this.checkboxesString
})
.then(()=>{
})
.catch((error)=>{
this.errorMessage=error;
console.log('unable to save the record due to'+JSON.stringify(this.errorMessage));
});
}
}