field disappear after implementing java snippet

  • 1
  • Question
  • Updated 10 months ago
  • In Progress
I have a field which is being rendered on basis of java snippet.

But if I am including that field in field editor. Whole Field editor will get disappear.


Here is Java Snippet code:

var element = arguments[0],value = arguments[1],$ = skuid.$;

    //Get Lead model information
    var leadmodel = skuid.model.getModel("Lead");
    
    //Fetch first row of Lead info.
    var raw= leadmodel.getFirstRow();
    
    // Get Matter type field value
    var MatterType=raw.Matter_Type__c;
    
    var Attorney=raw.Attorney__c;
    
    // Get WLG office field value
    var wlgoffice=raw.WLG_Office__c;
    
    // Perform query on salesforce object on basis of Matter type and WLG office on Lead
    var result = sforce.connection.query("SELECT                       
                                         Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id
                                         FROM Consulting_Attorney__c where Matter_Type__c
                                         ='"+MatterType+"'AND Wlg_Office__c ='"+wlgoffice+"'"); 

    var Att = result.getArray("records");
    console.log(Att);
    
if(Att.length!==0 && Att[0].Attornies__c!==undefined)
{
    var array = Att[0].Attornies__c.split(',');
    var records = array.toString().replace(/,/g , "','"); 

    // Fetch Salesforce users informations
    var result1 = sforce.connection.query("SELECT id,name FROM user WHERE Id in 
      ('"+records+"')");  

     var Users = result1.getArray("records");
 
    // Create a array for Custom Picklist
    var picklistEntries = [];

    picklistEntries = element.metadata.picklistEntries;

    // if you don't do this, then the "real" values are already in the picklist and the code below will           add duplicate values
   
 picklistEntries.length = 0;     
        
        
       for(var a=0;a<Users.length;a++){
           
            picklistEntries.push( { value:Users[a].id , label:Users[a].Name, defaultValue: false, active: true  });
           
        }
    skuid.ui.fieldRenderers[element.metadata.displaytype][element.mode](element,value);
}


And also if i will remove if condition from above code, I am facing same issue.

Please help as this is urgent.
Photo of Gopal Agrawal

Gopal Agrawal

  • 598 Points 500 badge 2x thumb

Posted 11 months ago

  • 1
Photo of Gopal Agrawal

Gopal Agrawal

  • 598 Points 500 badge 2x thumb
Hi,

I have gone through line by line code.

And found that

There is problem with 

var result = sforce.connection.query("SELECT                       
                                         Name,Attorney__c,Matter_Type__c,Wlg_Office__c,Attornies__c,Id 
                                         FROM Consulting_Attorney__c where Matter_Type__c 
                                         ='"+MatterType+"'AND Wlg_Office__c ='"+wlgoffice+"'"); 

Once i remove it from snippet.

field appears


Could any one suggest , what is wrong with this query.
(Edited)
Photo of Rajat Maheshwari

Rajat Maheshwari

  • 420 Points 250 badge 2x thumb
Hi Matt,

As per you told us to log the element at start, I have done and here is the results : - 

  1. Object
    1. component:Y {accessible: true, createable: true, updateable: true, deleteable: true, readonly: false, ...}
    2. context:{model: Y, initiatorId: 42, event: "row.updated", modelId: "Lead", rowId: "00Qc000000AOdLMEA1", ...}
    3. event:"row.updated"
    4. initiatorId:42
    5. model:Y {accessible: true, createable: true, updateable: true, deleteable: true, readonly: false, ...}
    6. modelHadPriorChanges:false
    7. modelId:"Lead"
    8. row:{attributes: {...}, LastName: "jacqueline", CreatedDate: "2017-11-15T07:54:03.000+0000", Address: null, Are_you_and_spouse_residing_together__c: false, ...}
    9. rowHadPriorChanges:false
    10. rowId:"00Qc000000AOdLMEA1"
    11. updates:{Matter_Type__c: "Annulment"}
    12. __proto__:Object



For screenshot about config the skuid builder where we are calling snippet :  -
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Hmm. From the arguments that are getting passed to the snippet, it looks like the snippet is being run from a model action. Do you have any model actions set up that might be running this snippet?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Also, what are you getting for 'value' at the beginning of the snippet?
Photo of Rajat Maheshwari

Rajat Maheshwari

  • 420 Points 250 badge 2x thumb
Hi Matt,

Hope you are doing great :)

No, we are not using model actions set up that running this snippet.

When we put console log for value, First time it says : --None-- and then It gives "Undefined".

Thanks