How to populate ui only picklist field through apex code.

Rahul,

You may not need to use Apex.  If the data that drives the pick list is in an object, you can drive the pick list options using a model in Skuid.  Here is a posting where I provided a sample page that shows you how to do this:

https://community.skuid.com/t/how-to-bind-skuid-picklist-ui-field-from-snippet

If you still want to go down the path of using an Apex class, then you can Salesforce’s JS library to call an Apex Class directly.  The function call is ‘sforce.apex.execute’.  Here is a nice write up from Zach on what you need to do:

https://community.skuid.com/t/calling-apex-function

Here is an example of a snippet to build and render a custom pick list values on a UI only field:

https://community.skuid.com/t/ui-only-picklist-custom-field-renderer-snippet-stopped-work…


I would recommend that you consider how you can setup an object to act as a source for your pick list options.  This will keep your page declarative and greatly reduce what you have to maintain going forward.

Thanks,

Bill

Thanks you very much Bill for your reply.
I have to use an apex class as the picklist values are based on some condition and dynamic as well.
But as per the code below I am not able to populate the values. Can you please help me out.

var params = arguments[0],
$ = skuid.$;
var productRow = skuid.model.getModel(‘GeneralProduct’).getFirstRow();
var applicationModel = skuid.model.getModel(‘GeneralApplication’);


var appModel = skuid.model.getModel(‘CommonApplicationModel’);
var appRow = appModel.data[0];
var ret = sforce.apex.execute(“apexClass”,“apexMethod”,{AppId:appRow.Id});
var test = applicationModel.getField(‘Team_users’);

   var raw= appModel.getFirstRow();

var field = arguments[0];
var result = {
    ‘genesis__Applications__c’ : applicationModel,
};

return result;

var raw= appModel.getFirstRow();
 var UserType=raw.Team_users;
 
 var picklistEntries = ;

picklistEntries = element.metadata.picklistEntries;
picklistEntries.length = 0;  

for(var a=0;a<ret.length;a++){
            picklistEntries.push( { value:ret[a].Name , label:ret[a].Name, defaultValue: false, active: true  });
        }
skuid.ui.fieldRenderers[element.metadata.displaytype]element.mode;
field.metadata.picklistEntries = picklistEntries;

Rahul,

The line "return result;’ will stop the execution of your script at that line.  The remaining code that actually adds the pick list entries will never run.  Also, in your second to last line (skuid.ui.fieldRenderers[element.metadata.displaytype]element.mode;), you reference ‘element’ which you have not defined–this should be ‘field’ instead of ‘element’.

There also seems to be some extra code that is not needed to render the picklist field.  I would remove this code.  Here is what I would recommend you use as your custom render Snippet:

var field = arguments[0],<br>$ = skuid.$;<br><br>var ret = sforce.apex.execute("apexClass","apexMethod",{AppId:appRow.Id});<br><br>var picklistEntries = field.metadata.picklistEntries;<br>picklistEntries.length = 0;&nbsp;&nbsp;<br><br>for(var a=0;a&lt;ret.length;a++){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picklistEntries.push( { value:ret[a].Name , label:ret[a].Name, defaultValue: false, active: true&nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);


Thanks,

Bill

Thank you so much Bill for your reply.
My code is failing in line var picklistEntries = field.metadata.picklistEntries;
I checked by using alert and nothing is coming up. Can you please help

Rahul,

Try adding a pick list entry to your UI only field.  Also make sure that your UI only field is display type ‘picklist’.

Thanks,

Bill