Skip to main content

#LWC Javascript Files0 人正在讨论

Hi,

 

The below MIME type is not working in LWC while generating the excel

'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.

may i know any suggestions/correction/other methods to generate excel of type xlsx apart from uploading JS file to static resource?

 

#LWC Development #LWC Components #Apex #LWC Javascript Files

 

Thanks

0/9000

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

import retrieveContacts from '@salesforce/apex/downloadContcatApexClass.retrieveContactMethod';

export default class DownloadContacts extends LightningElement {

@api recordId;

@track contacts;

@track error;

@api invoke(){

retrieveContacts({ recordIdAccount: this.recordId })

.then((result) => {

console.log('line 12:' + result);

this.contacts = result;

this.error = undefined;

})

.catch((error) => {

this.error = error;

this.contacts = undefined;

});

var columnEnd = ',';

var lineEnd = '\n';

// Get the CSV header from the list.

var keys = new Set();

this.contacts.forEach(function (record) {

Object.keys(record).forEach(function (key) {

keys.add(key);

});

});

keys = Array.from(keys);

var csvString = '';

csvString += keys.join(columnEnd);

csvString += lineEnd;

for (var i = 0; i < this.contacts.length; i++) {

var counter = 0;

for (var sTempkey in keys) {

var skey = keys[sTempkey];

// add , after every value except the first.

if (counter > 0) {

csvString += columnEnd;

}

// If the column is undefined, leave it as blank in the CSV file.

var value = this.contacts[i][skey] === undefined ? '' : this.contacts[i][skey];

csvString += '"' + value + '"';

counter++;

}

csvString += lineEnd;

var hiddenElement = document.createElement('a');

hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);

hiddenElement.target = '_self';

//hiddenElement.download = component.get("v.fileName");

document.body.appendChild(hiddenElement); //Required for FireFox browser

hiddenElement.click(); // using click() js function to download csv file

}

}

}

 

I have to create lwc quick action to convert related contacts in to csv download. i had  created lwc quick action button and retrieved the data needed.there is problem in converting to csv. I have tried everything .below is my code. thanks in advance for any help.please help.

 

ERROR :-Cannot read properties of undefined (reading 'forEach')

 

#LWC Components  #LWC  #LWC Component  #Lightning Web Components  #Lightning  #LWC Development  #Custom LWC  #LWC Javascript Files

2 个回答
  1. 2021年10月27日 04:45

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

    import retrieveContacts from '@salesforce/apex/downloadContcatApexClass.retrieveContactMethod';

    export default class DownloadContacts extends LightningElement {

    @api recordId;

    @track contacts;

    @track error;

    @api invoke(){

    retrieveContacts({ recordIdAccount: this.recordId })

    .then((result) => {

    console.log('line 12:' + result);

    this.contacts = result;

    this.error = undefined;

    var columnEnd = ',';

    var lineEnd = '\n';

    // Get the CSV header from the list.

    var keys = new Set();

    this.contacts.forEach(function (record) {

    Object.keys(record).forEach(function (key) {

    keys.add(key);

    });

    });

    keys = Array.from(keys);

    var csvString = '';

    csvString += keys.join(columnEnd);

    csvString += lineEnd;

    for (var i = 0; i < this.contacts.length; i++) {

    var counter = 0;

    for (var sTempkey in keys) {

    var skey = keys[sTempkey];

    // add , after every value except the first.

    if (counter > 0) {

    csvString += columnEnd;

    }

    // If the column is undefined, leave it as blank in the CSV file.

    var value = this.contacts[i][skey] === undefined ? '' : this.contacts[i][skey];

    csvString += '"' + value + '"';

    counter++;

    }

    csvString += lineEnd;

    var hiddenElement = document.createElement('a');

    hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);

    hiddenElement.target = '_self';

    //hiddenElement.download = component.get("v.fileName");

    document.body.appendChild(hiddenElement); //Required for FireFox browser

    hiddenElement.click(); // using click() js function to download csv file

    }

    })

    .catch((error) => {

    this.error = error;

    this.contacts = undefined;

    });

    }

    }

0/9000

Hey there!

Can anybody help me for the query in lwc - 

#LWC Component  #LWC  #LWC Javascript Files  #Integration 

 

How to get data values from [object Object] in html comming from @wire method @wire(getSearchDetails,{crnno:'$parentData'}) searchDtls;

1 个回答
0/9000

Can anybody help me for the query in lwc -

 

#LWC Component  #LWC  #LWC Javascript Files  #Integration

 

How to get data values from [object Object] in html comming from @wire method 

@wire(getSearchDetails,{crnno:'$parentData'}) searchDtls;

2 个回答
  1. 2021年8月28日 18:41

    @Harikesh,

     

    When i try to print the object sent by Apex its showing as [object Object] . Actually this is an Wrapper class object which has two string fields. I want to retrieve the values of strings from object got from Apex and display in html. Hope it helps in understanding my question. Thanks for the help

0/9000

Create an LWC component where we want to map fields of two objects. For eg,

 

we need to use schema class to get fields and mapping. Similar to lead mapping. 

 

We need that to be dynamic 

 

we can select source and destination object 

 

#LWC #LWC Component #LWC Superbadge Challenge #Custom LWC #LWC Development #LWCblogs #LWC Javascript Files #LWC Framework #LWC Vs Aura Performance

3 个回答
0/9000

Hi All,

 

I am trying to migrate a VF page to LWCs and was wondering if LWC javascript files do allow forEach() loops?

I have used them in auraComponents but ESLint is marking my loop as unexpected token when used in LWC javascript in VS Code.

 

I couldn't find any documentation about this.

And, my console.log() statements don't appear in the browser logs but the alert() statements for the same works fine. Note: I did except console and alert statements in eslintrc config file.

 

Thanks

Naga

2 条评论
0/9000