2

I'm creating a lightning application who show by whom fields are editable. For that, I have that lightning component :

 <aura:component controller="testmap">
<!-- initialazing the first select list -->
<aura:handler name="init" action="{!c.Initialize}" value="{!this}" /> 
<!-- creating the 3 attribute in use -->
<aura:attribute name="item" type="String[]" default='' required="false" />
<aura:attribute name="ItemField" type="String[]" default='' required="false" />
<aura:attribute name="Permissions" type="Sobject[]"  required="false" />
<h1 align="center">Liste des droits pour un champ</h1><br/> <br />
<p>il peut être nécessaire d'attendre quelques instants avant que le menu ne se charge</p>
<!-- First list, works fine -->
<ui:inputSelect aura:id="LD" label="Object Levels" change="{!c.SelectChangement}">
    <aura:iteration items="{!v.item}" var="Objet">
        <ui:inputSelectOption text="{!Objet}" label="{!Objet}"/>
    </aura:iteration>
</ui:inputSelect>
<p>Si vous souhaitez selectionner le première champ, veuillez selectionner un autre champ avant</p>
<!-- Second list, works fine -->
<ui:inputSelect aura:id="Liste2" label="Fields Levels">
    <aura:iteration items="{!v.ItemField}" var="champ">
        <ui:inputSelectOption text="{!champ}" label="{!champ}"/>
    </aura:iteration>
</ui:inputSelect> 
<!-- When pressing the button, it calls a function with the two fields precendently selected as input -->
<ui:button label="Presse moi pour savoir les permissions" press="{!c.FindPerm}" /> 
<br/>
<!-- Table where the result is shown -->
<table>
    <aura:iteration items="{!v.Permissions}" var="perm">
        <!-- Display names of all accounts -->
        <tr><td>
            <div>{!perm.NomProfil}</div></td><td>{!perm.IsEdit}</td><td>{!perm.IsRead} </td></tr>
    </aura:iteration>


</table>

which access 3 javascript function. The first two work just fine, and the third supposedely so, but I cannot see the result.

This is the javascript function I call to update {!v.Permission} :

     FindPerm : function(cmp,event){
    var Perm = cmp.get("c.Recherche");
    var objetselec = cmp.find("LD").get("v.value");
    var champ = cmp.find("Liste2").get("v.value");

  Perm.setParams({
        Objet : objetselec,
      NomField : champ          
                });
  // system.log(Perm);
  Perm.setCallback(this, function(rep) {
            var state = rep.getState();
                if (state === "SUCCESS") {
                    var stringItems = rep.getReturnValue();
                    if(stringItems != null){
                        console.log("stringItems.NomProfil : " +stringItems.NomProfil);


                        console.log("stringItems.IsEdit : " +stringItems.IsEdit);

                        console.log("stringItems.IsRead : " +stringItems.IsRead);


                    }

                    cmp.set("v.Permissions.IsEdit", stringItems.IsEdit);
                    cmp.set("v.Permissions.IsRead", stringItems.IsRead);
                    cmp.set("v.Permissions.NomProfil",stringItems.NomProfil);
                    console.log(cmp.get("v.Permissions.IsEdit"));
                    console.log(cmp.get("v.Permissions.IsRead"));
                    console.log(cmp.get("v.Permissions.NomProfil"));
                    console.log(cmp.get("v.Permissions"));
                }

            });
           $A.enqueueAction(Perm);
        }

the console debug display me this : screenshot DisplayConsole

So, Permissions exists, the 3 arrays too, but my iteration cannot access it. When i create an iteration like the following :

        <aura:iteration items="{!v.Permissions.NomProfil}" var="perm">
              {!perm} <br/>
        </aura:iteration>

The application displays all my profile names.

Anyone knows why it does this ?

Thank you !

EDIT : There is the backed apex controller :

      global class VarTmp{
    @AuraEnabled
    global List<String> NomProfil {get;set;}
    @AuraEnabled
    global List<String> IsEdit {get;set;}
    @AuraEnabled
    global  List<String> IsRead {get;set;}

    global VarTmp(){
        NomProfil = new List<String>();
        IsEdit = new List<String>();
        IsRead = new List<String>();
    }
}
   @AuraEnabled
public static VarTmp Recherche(String Objet ,String NomField) {
    //Requete dans FieldPermission afin de trouver l'ID de la permission

    VarTmp Variable = new VarTmp();

    List<FieldPermissions> IdPerm = [SELECT ParentId , PermissionsEdit, PermissionsRead From FieldPermissions
                                     WHERE Field =: NomField AND SobjectType=:Objet ];
    Map<id, FieldPermissions>IdTri= new Map<id, FieldPermissions>();

    Integer NbrComptes = IdPerm.size();
    system.debug(IdPerm);

    for(Integer i=0; i<NbrComptes; i++) {
        IdTri.put(IdPerm.get(i).ParentID, IdPerm.get(i));
    }        
    system.debug(IdTri);
    If (IdPerm.isEmpty()) {
        System.debug('Le champ que vous recherchez n"existe pas, veuillez chercher à nouveau');
    }
    System.debug(IdPerm.size());



    //Requete dans PermissionSet afin de trouver l'ID des profils concernés
    List<PermissionSet> IdProfile = [SELECT ProfileId,Profile.Name FROM PermissionSet 
                                     WHERE  IsOwnedByProfile=true];

    List<PermissionSet> PermissionSetName  =[SELECT Label FROM PermissionSet 
                                            Where ProfileID =''];

    Map<id, PermissionSet>IdTriProfil= new Map<id, PermissionSet>();
    Map<id, PermissionSet>IdTriPermission = new Map<id, PermissionSet>();
    Integer NbrComptes2 = IdProfile.size();

    for(Integer i=0; i<NbrComptes2; i++) {
      IdTriProfil.put(IdProfile.get(i).Id, IdProfile.get(i));

    } 

    Integer NbrComptes3 = PermissionSetName.size();

    for(Integer i=0; i<NbrComptes3; i++) {
      IdTriPermission.put(PermissionSetName.get(i).Id, PermissionSetName.get(i));
    }          
        List<ID> IdKeyTotal = new List<ID>();
        IdKeyTotal.addAll( IdTriProfil.keySet());
        for(ID IdKey :IdKeyTotal ) {
            if(idTri.containsKey(IdKey)) {
            Variable.NomProfil.add(idTriProfil.get(IdKey).Profile.Name);

            if(IdTri.get(IdKey).PermissionsEdit ==true){
                Variable.IsEdit.add('Aye');
            }else{
                Variable.IsEdit.add('Nei');
            }
              if(IdTri.get(IdKey).PermissionsRead ==true) {
                Variable.IsRead.add('Aye');
            }else{
                Variable.IsRead.add('Nei');
            }//else {
            }    
            else if(idTriPermission.containsKey(IdKey)){
                Variable.NomProfil.add(IdTriPermission.get(IdKey).Label);
            }
            else{
                Variable.NomProfil.add(IdTriProfil.get(IdKey).Profile.Name);
                Variable.IsRead.add('Nei');
                Variable.IsEdit.add('Nei');
            }
        }     




    system.debug(IdTri.keySet());
    system.debug(IdTriPermission.keySet());
    system.debug(IdTriProfil.keySet()); 
    system.debug(Variable);    
    return Variable;
}
1
  • Could you also share backend apex code to help you debug? Mar 22, 2017 at 14:05

1 Answer 1

2

Problem solved !

instead of using a class like this :

 global class VarTmp{
    @AuraEnabled
    global List<String> NomProfil {get;set;}
    @AuraEnabled
    global List<String> IsEdit {get;set;}
    @AuraEnabled
    global  List<String> IsRead {get;set;}

    global VarTmp(){
        NomProfil = new List<String>();
        IsEdit = new List<String>();
        IsRead = new List<String>();
    }

I used one who look like this :

    global class ProfilPermission{
    @AuraEnabled
    global String NomProfil {get;set;}
    @AuraEnabled
    global String IsEdit {get;set;}
    @AuraEnabled
    global  String IsRead {get;set;}

}

I was using a class with lists inside, now I update a list with elements from my class instead.

So this :

   for(ID IdKey :IdKeyTotal ) {
            if(idTri.containsKey(IdKey)) {
            Variable.NomProfil.add(idTriProfil.get(IdKey).Profile.Name);

            if(IdTri.get(IdKey).PermissionsEdit ==true){
                Variable.IsEdit.add('Aye');
            }else{
                Variable.IsEdit.add('Nei');
            }
              if(IdTri.get(IdKey).PermissionsRead ==true) {
                Variable.IsRead.add('Aye');
            }else{
                Variable.IsRead.add('Nei');
            }//else {
            }    
            else if(idTriPermission.containsKey(IdKey)){
                Variable.NomProfil.add(IdTriPermission.get(IdKey).Label);
            }
            else{
                Variable.NomProfil.add(IdTriProfil.get(IdKey).Profile.Name);
                Variable.IsRead.add('Nei');
                Variable.IsEdit.add('Nei');
            }
        }     

Became that :

   for(ID IdKey :IdKeyTotal ) {
            ProfilPermission profilPermission = new ProfilPermission();

            if(idTri.containsKey(IdKey)) {
            profilPermission.NomProfil = (idTriProfil.get(IdKey).Profile.Name);

            if(IdTri.get(IdKey).PermissionsEdit ==true){
               profilPermission.IsEdit = 'Aye';
            }else{
                profilPermission.IsEdit = 'Nei';
            }
              if(IdTri.get(IdKey).PermissionsRead ==true) {
                profilPermission.IsRead = 'Aye';
            }else{
                profilPermission.IsRead = 'Nei';
            }
            }
            else if(idTriPermission.containsKey(IdKey)){
                profilPermission.NomProfil = (IdTriPermission.get(IdKey).Label);
            }
            else{
               profilPermission.NomProfil = (IdTriProfil.get(IdKey).Profile.Name);
                profilPermission.IsEdit = 'Nei';
               profilPermission.IsRead = 'Nei';
            }
            listOfProfilPermission.add(profilPermission);
            System.debug(profilPermission);

        }     

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .