You are on page 1of 6

import { LightningElement, api, wire, track } from 'lwc';

import getPatientData from '@salesforce/apex/PatientDataService.getPatientData';

export default class TestDevice extends LightningElement {


@api recordId; // This will hold the ID of the record that's currently being
viewed.
@track value; // This will hold the selected value.
@track options = []; // This will hold the picklist options.

connectedCallback() {
console.log('Record ID: ', this.recordId, 'line 10'); // Log the recordId
when the component is inserted into the DOM.
}

// Use the getPatientData Apex method to get the RPMDeviceID__c and


RPMDeviceID_2__c fields of the related patient.
@wire(getPatientData, { encounterId: '$recordId' })
wiredPatientData({ error, data }) {
if (data) {
console.log(data);
// If we successfully got the record, add the device IDs as options.
this.options = [
{ label: data.RPMDeviceID__c, value: data.RPMDeviceID__c },
{ label: data.RPMDeviceID_2__c, value: data.RPMDeviceID_2__c }
];
// Set the default value to the first option
this.value = this.options[0].value;
} else if (error) {
console.error(error);
// Handle any errors.
console.error(error);
// If no data is returned, add a 'None' option to the combobox.
this.options = [{ label: 'None', value: 'None' }];
this.value = 'None';
}
}

// This method handles changes to the combobox.


handleChange(event) {
this.value = event.detail.value;
// Get a reference to the recordEditForm component
const recordEditForm = this.template.querySelector('lightning-record-edit-
form');
// Get a reference to the field to update
const fields = {};
fields['testingfield__c'] = this.value;
// Update the field
recordEditForm.submit(fields);
}
}
-----------------------------------------------------------------------------------
-------------------

import { LightningElement, api, wire, track } from 'lwc';


import getPatientData from '@salesforce/apex/PatientDataService.getPatientData';

export default class TestDevice extends LightningElement {


@api recordId; // This will hold the ID of the record that's currently being
viewed.
@track value; // This will hold the selected value.
@track options = []; // This will hold the picklist options.

connectedCallback() {
console.log('Record ID: ', this.recordId, 'line 10'); // Log the recordId
when the component is inserted into the DOM.
// Submit the initial value
this.submitValue(this.value);
}

// Use the getPatientData Apex method to get the RPMDeviceID__c and


RPMDeviceID_2__c fields of the related patient.
@wire(getPatientData, { encounterId: '$recordId' })
wiredPatientData({ error, data }) {
if (data) {
console.log(data);
// If we successfully got the record, add the device IDs as options.
this.options = [
{ label: data.RPMDeviceID__c, value: data.RPMDeviceID__c },
{ label: data.RPMDeviceID_2__c, value: data.RPMDeviceID_2__c }
];
// Set the default value to the first option
this.value = this.options[0].value;
// Submit the default value
this.submitValue(this.value);
} else if (error) {
console.error(error);
// Handle any errors.
console.error(error);
// If no data is returned, add a 'None' option to the combobox.
this.options = [{ label: 'None', value: 'None' }];
this.value = 'None';
// Submit the default value
this.submitValue(this.value);
}
}

submitValue(value) {
// Get a reference to the recordEditForm component
const recordEditForm = this.template.querySelector('lightning-record-edit-
form');
// Check if recordEditForm is not null
if(recordEditForm) {
// Get a reference to the field to update
const fields = {};
fields['testingfield__c'] = value;
// Update the field
recordEditForm.submit(fields);
}
}

// This method handles changes to the combobox.


handleChange(event) {
this.value = event.detail.value;
// Submit the new value
this.submitValue(this.value);
}
}
-----------------------------------------------------------------------------------
----------------------

import { LightningElement, api, wire, track } from 'lwc';


import getPatientData from '@salesforce/apex/PatientDataService.getPatientData';

export default class TestDevice extends LightningElement {


@api recordId; // This will hold the ID of the record that's currently being
viewed.
@track value; // This will hold the selected value.
@track options = []; // This will hold the picklist options.

renderedCallback() {
// Submit the initial value
this.submitValue(this.value);
}

// Use the getPatientData Apex method to get the RPMDeviceID__c and


RPMDeviceID_2__c fields of the related patient.
@wire(getPatientData, { encounterId: '$recordId' })
wiredPatientData({ error, data }) {
if (data) {
console.log(data);
// If we successfully got the record, add the device IDs as options.
this.options = [
{ label: data.RPMDeviceID__c, value: data.RPMDeviceID__c },
{ label: data.RPMDeviceID_2__c, value: data.RPMDeviceID_2__c }
];
// Set the default value to the first option
this.value = this.options[0].value;
} else if (error) {
console.error(error);
// Handle any errors.
console.error(error);
// If no data is returned, add a 'None' option to the combobox.
this.options = [{ label: 'None', value: 'None' }];
this.value = 'None';
}
}

submitValue(value) {
// Get a reference to the recordEditForm component
const recordEditForm = this.template.querySelector('lightning-record-edit-
form');
// Check if recordEditForm is not null
if(recordEditForm) {
// Get a reference to the field to update
const fields = {};
fields['testingfield__c'] = value;
// Update the field
recordEditForm.submit(fields);
}
}

// This method handles changes to the combobox.


handleChange(event) {
this.value = event.detail.value;
// Submit the new value
this.submitValue(this.value);
}
}
-----------------------------------------------------------------------------------
---------------------

import { LightningElement, api, wire, track } from 'lwc';


import { getRecord } from 'lightning/uiRecordApi';
import getPatientData from '@salesforce/apex/PatientDataService.getPatientData';

export default class TestDevice extends LightningElement {


@api recordId; // This will hold the ID of the record that's currently being
viewed.
@track value; // This will hold the selected value.
@track options = []; // This will hold the picklist options.

// Use the getRecord wire adapter to watch for changes in the record
@wire(getRecord, { recordId: '$recordId', fields: ['Patient__c.RPMDeviceID__c',
'Patient__c.RPMDeviceID_2__c'] })
record;

renderedCallback() {
// Submit the initial value
this.submitValue(this.value);
}

// Use the getPatientData Apex method to get the RPMDeviceID__c and


RPMDeviceID_2__c fields of the related patient.
@wire(getPatientData, { encounterId: '$recordId' })
wiredPatientData({ error, data }) {
if (data) {
console.log(data);
// If we successfully got the record, add the device IDs as options.
this.options = [
{ label: data.RPMDeviceID__c, value: data.RPMDeviceID__c },
{ label: data.RPMDeviceID_2__c, value: data.RPMDeviceID_2__c }
];
// Set the default value to the first option
this.value = this.options[0].value;
} else if (error) {
console.error(error);
// Handle any errors.
console.error(error);
// If no data is returned, add a 'None' option to the combobox.
this.options = [{ label: 'None', value: 'None' }];
this.value = 'None';
}
}

submitValue(value) {
// Get a reference to the recordEditForm component
const recordEditForm = this.template.querySelector('lightning-record-edit-
form');
// Check if recordEditForm is not null
if(recordEditForm) {
// Get a reference to the field to update
const fields = {};
fields['testingfield__c'] = value;
// Update the field
recordEditForm.submit(fields);
}
}

// This method handles changes to the combobox.


handleChange(event) {
this.value = event.detail.value;
// Submit the new value
this.submitValue(this.value);
}
}
-----------------------------------------------------------------------------------
--------------------

import { LightningElement, api, wire, track } from 'lwc';


import { getRecord } from 'lightning/uiRecordApi';
import getPatientData from '@salesforce/apex/PatientDataService.getPatientData';

export default class TestDevice extends LightningElement {


@api recordId;
@track value = 'None';
@track options = [{ label: 'None', value: 'None' }];

@wire(getRecord, { recordId: '$recordId', fields: ['Patient__c.RPMDeviceID__c',


'Patient__c.RPMDeviceID_2__c'] })
record;

renderedCallback() {
this.submitValue(this.value);
}

@wire(getPatientData, { encounterId: '$recordId' })


wiredPatientData({ error, data }) {
if (data) {
this.options = [];
if (data.RPMDeviceID__c) {
this.options.push({ label: data.RPMDeviceID__c, value:
data.RPMDeviceID__c });
}
if (data.RPMDeviceID_2__c) {
this.options.push({ label: data.RPMDeviceID_2__c, value:
data.RPMDeviceID_2__c });
}
if (this.options.length === 0) {
this.options.push({ label: 'None', value: 'None' });
}
this.value = this.options[0].value;
this.submitValue(this.value);
} else if (error) {
console.error(error);
this.options = [{ label: 'None', value: 'None' }];
this.value = 'None';
this.submitValue(this.value);
}
}

submitValue(value) {
const recordEditForm = this.template.querySelector('lightning-record-edit-
form');
if(recordEditForm) {
const fields = {};
fields['testingfield__c'] = value;
recordEditForm.submit(fields);
}
}

handleChange(event) {
this.value = event.detail.value;
this.submitValue(this.value);
}
}

You might also like