From 017ea2dde422c510b87759b821035f712c028e43 Mon Sep 17 00:00:00 2001
From: iDamari <16044414+iDamari@users.noreply.github.com>
Date: Tue, 28 Jan 2025 20:59:45 +0200
Subject: [PATCH 1/2] =?UTF-8?q?feat:=20extend=20Quick=20Lookup=20aura=20co?=
=?UTF-8?q?mponent=20with=20barcode=20reader=20support.=20=E2=9C=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../QuickLightningLookup.cmp | 4 +
.../QuickLightningLookupController.js | 8 +-
.../default/aura/quickLookup/quickLookup.cmp | 14 ++-
.../aura/quickLookup/quickLookup.design | 1 +
.../aura/quickLookup/quickLookupController.js | 19 +++++
.../fsc_barcodeScanner.html | 7 ++
.../fsc_barcodeScanner/fsc_barcodeScanner.js | 85 +++++++++++++++++++
.../fsc_barcodeScanner.js-meta.xml | 14 +++
8 files changed, 149 insertions(+), 3 deletions(-)
create mode 100644 flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.html
create mode 100644 flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js
create mode 100644 flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js-meta.xml
diff --git a/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookup.cmp b/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookup.cmp
index 82d848bf6..c9762d209 100644
--- a/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookup.cmp
+++ b/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookup.cmp
@@ -113,6 +113,10 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+
+
diff --git a/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookupController.js b/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookupController.js
index df416f906..48a6816c9 100644
--- a/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookupController.js
+++ b/flow_screen_components/quickLookup/force-app/main/default/aura/QuickLightningLookup/QuickLightningLookupController.js
@@ -33,7 +33,13 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
helper.hideDropDown(component);
}
}, false));
-
+ },
+ handleInvokeLookup : function(component, event, helper) {
+ const { searchString } = event.getParam("arguments");
+ if(searchString) {
+ document.getElementById(component.getGlobalId() + "_myinput").value = searchString;
+ helper.hlpPerformLookup(component);
+ }
},
performLookup : function(component, event, helper) {
helper.hlpPerformLookup(component);
diff --git a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.cmp b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.cmp
index 7280ecd55..68f74a574 100644
--- a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.cmp
+++ b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.cmp
@@ -23,6 +23,8 @@
+
+
@@ -34,14 +36,22 @@
{!v.label}
-
-
+
+
+
+
+
+
+
+
diff --git a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.design b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.design
index 3af1e756c..e34376d13 100644
--- a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.design
+++ b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookup.design
@@ -17,5 +17,6 @@
+
diff --git a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js
index 829fdafd4..28ec730a3 100644
--- a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js
+++ b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js
@@ -1,5 +1,24 @@
({
doInit: function (component, event, helper) {
helper.hlpCheckValidity(component, event);
+ },
+ handleScanSuccess: function (component, event, helper) {
+ component.set('v.errorMessage', '');
+ //component.set("v.filterFieldValue", scannedBarcode);
+ const componentA = component.find('QuickLightningLookup');
+ const scannedBarcode = event.getParam('value');
+ componentA.invokeLookup(scannedBarcode);
+ },
+ handleScanError: function (component, event, helper) {
+ const errorMessage = event.getParam('detail');
+ var toast = $A.get('e.force:showToast');
+ if (toast) {
+ //fire the toast event in Salesforce app and Lightning Experience
+ toast.setParams({
+ title: 'Error!',
+ message: errorMessage
+ });
+ toast.fire();
+ }
}
});
\ No newline at end of file
diff --git a/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.html b/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.html
new file mode 100644
index 000000000..a2eb7a692
--- /dev/null
+++ b/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.html
@@ -0,0 +1,7 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js b/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js
new file mode 100644
index 000000000..cb1c1ffc9
--- /dev/null
+++ b/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js
@@ -0,0 +1,85 @@
+import { LightningElement, api, track } from 'lwc';
+import { ShowToastEvent } from 'lightning/platformShowToastEvent';
+import { getBarcodeScanner } from 'lightning/mobileCapabilities';
+import { FlowAttributeChangeEvent } from 'lightning/flowSupport';
+
+export default class fsc_barcodeScanner extends LightningElement {
+ barcodeScanner;
+ scannerDisabled = false;
+ @track barcodeScannedValue;
+ @api
+ get barcodeScanned() {
+ return this.barcodeScannedValue;
+ }
+ set barcodeScanned(value) {
+ this.barcodeScannedValue = value;
+ }
+
+ connectedCallback() {
+ this.barcodeScanner = getBarcodeScanner();
+ if (this.barcodeScanner == null || !this.barcodeScanner.isAvailable()) {
+ this.scannerDisabled = true;
+ }
+ }
+
+ handleBeginScanClick() {
+ const scanningOptions = {
+ scannerSize: 'XLARGE',
+ cameraFacing: 'BACK',
+ showSuccessCheckMark: true,
+ vibrateOnSuccess: true,
+ manualConfirmation: true,
+ previewBarcodeData: true,
+ enableBulkScan: false,
+ enableMultiScan: false
+ };
+
+ this.barcodeScannedValue = '';
+ if (this.barcodeScanner != null && this.barcodeScanner.isAvailable()) {
+ this.barcodeScanner
+ .scan(scanningOptions)
+ .then((result) => {
+ this.handleScannedBarcodes(result);
+ })
+ .catch((error) => {
+ this.handleError(error);
+ })
+ .finally(() => {
+ this.barcodeScanner.dismiss();
+ });
+ } else {
+ this.showToast('Barcode Scanner Is Not Available', 'Try again from the Salesforce app on a mobile device.', 'error', 'sticky');
+ }
+ }
+
+ handleScannedBarcodes(barcode) {
+ console.log(JSON.stringify(barcode));
+ if (barcode && barcode.length > 0) {
+ const value = barcode[0]?.value; //decodeURIComponent
+ this.barcodeScannedValue = value;
+ this.dispatchEvent(new CustomEvent('scansuccess', { detail: { value } }));
+
+ this.dispatchEvent(new CustomEvent('notifychange', { detail: { value: value } }));
+
+ const attributeChangeEvent = new FlowAttributeChangeEvent('barcodeScanned', value);
+ this.dispatchEvent(attributeChangeEvent);
+ }
+ }
+
+ showToast(title, message, variant, mode) {
+ this.dispatchEvent(
+ new ShowToastEvent({
+ title: title,
+ message: message,
+ variant: variant,
+ mode: mode
+ })
+ );
+ }
+
+ handleError(error) {
+ this.dispatchEvent(new CustomEvent('scanerror', { detail: error }));
+
+ this.showToast('Barcode Scanner Error', JSON.stringify(error), 'error', 'sticky');
+ }
+}
\ No newline at end of file
diff --git a/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js-meta.xml b/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js-meta.xml
new file mode 100644
index 000000000..22909cdb7
--- /dev/null
+++ b/flow_screen_components/quickLookup/force-app/main/default/lwc/fsc_barcodeScanner/fsc_barcodeScanner.js-meta.xml
@@ -0,0 +1,14 @@
+
+
+ 62.0
+ true
+ BarCode Scanner Action
+
+ lightning__FlowScreen
+
+
+
+
+
+
+
\ No newline at end of file
From a700efaf165de8a3818a92eab3361db1241a9506 Mon Sep 17 00:00:00 2001
From: iDamari <16044414+iDamari@users.noreply.github.com>
Date: Wed, 29 Jan 2025 12:53:56 +0200
Subject: [PATCH 2/2] code cleanup
---
.../main/default/aura/quickLookup/quickLookupController.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js
index 28ec730a3..38141e047 100644
--- a/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js
+++ b/flow_screen_components/quickLookup/force-app/main/default/aura/quickLookup/quickLookupController.js
@@ -2,9 +2,7 @@
doInit: function (component, event, helper) {
helper.hlpCheckValidity(component, event);
},
- handleScanSuccess: function (component, event, helper) {
- component.set('v.errorMessage', '');
- //component.set("v.filterFieldValue", scannedBarcode);
+ handleScanSuccess: function (component, event, helper) {
const componentA = component.find('QuickLightningLookup');
const scannedBarcode = event.getParam('value');
componentA.invokeLookup(scannedBarcode);