0

Hello everybody I am currently working on a Flow that receives the Id from the record where the LWC action is and pass it to the LWC.

The LWC is a form that shows some lightning-input and lightning-comboboxes and some of this lightning-input are empty so the user can fill them, but there are other lightning-input that I want to default show the value of the name and other fields from the record.

And also I want that every time the user clicks in the action button to show the Form with the populated fields I am troubling.

So in my apex class I created the next wrapper to return it to the LWC:

@AuraEnabled(cacheable= True)
public static WraperSObject getInformation(Id recordIdFlow){

    MySObject information = new MySObject();
    information = [SELECT Id, Name FROM MySObject WHERE Id =: recordIdFlow];

    WraperSObject wrapperPS = new WraperSObject();
    wrapperPS.name = puntoSuministro.Name;
    return wrapperPS;
}
public class WraperSObject{
    @AuraEnabled public String id{get;set;}
    @AuraEnabled public String name{get;set;}
}

And in my .js I have the next code:

cups; //variable where I want to put the value that comes from the wrapper.
wiredRecord;
@wire(getInformation,{recordIdFlow: 'recordId'})
wiredInfo(result){
    this.wiredRecord = result;
    console.log('information from wrapper'+ result);
    //dont know how to assign the value from the wrapper in the js variable
}

And in my .html the field is this:

<lightning-input type="text"  label="CUPS" max-length="22" name="cups"></lightning-input>

Could anybody help me?

Thanks

1 Answer 1

0

define a property -

defaultValue

when you iterate through the records using forEach or Iterator

do this-

this.defaultValue = arr[0]; (assuming arr is an array where you are pushing your retrieved results)

Do this in HTML - <lightning-input type="text" value={defaultValue} label="CUPS" max-length="22" name="cups"></lightning-input>

EDIT Have you Tried this?

@wire(getInformation,{recordIdFlow: 'recordId'}) wiredInfo({data,error}){
    if (data){
console.log(data); //inspect your results
this.cups = data;
}
else if(error){
console.log(error);
}
    }
2
  • could you explain a bit more? I am not getting it. Thanks
    – user120821
    Dec 6, 2022 at 20:04
  • Yeah I have the error part they are not Errors its information in a String. The problem is that I dont know how to evaluate if the string that comes has the word Error
    – user120821
    Dec 7, 2022 at 6:50

You must log in to answer this question.