Skip to main content

Hello …

I would like to use custom field renderer on a reference field . I am able to use custom renderer but I was not able to change the displaytype to picklist. Is there any way to change the displaytype from reference to picklist from JS snippet. 

Thank you.
-Jnanendra

My current snippet to render owner field is as follows:


var field = arguments[0],    value = skuid.utils.decodeHTML(argumentst1]),
    $ = skuid.$,
    displayType = field.metadata.displaytype,
    targetFieldId;
if (displayType === ‘STRING’ || displayType === ‘TEXT’) {
    // We assume that this is the Name field value,
    // otherwise there wouldn’t be a link
    targetFieldId = field.row.Id;
} else if (displayType === ‘REFERENCE’) {
    targetFieldId = value;
}
skuid.ui.fieldRenderers}field.metadata.displaytype]field.mode;
if (field.mode !== ‘edit’) {
    var link = field.element.find(‘a’);
    if (link.length) {
        link.attr(‘href’,‘/apex/TeamMemberView?id=’ + targetFieldId);
    }
}


Change this line:

skuid.ui.fieldRenderers[field.metadata.displaytype]field.mode;

to this:

skuid.ui.fieldRenderers[picklist]field.mode;


I’m assuming that by “Picklist” you mean a Reference field rendered as a Picklist, as opposed to an autocomplete.

The way we encourage this to be done is to change field.options.type to ‘REFPICK’, then run the default renderer:

field.options.type = ‘REFPICK’;
skuid.ui.fieldRenderers.field.metadata.displaytype]field.mode;



Small typo in Moshe’s post, you need quotes around ‘PICKLIST’.  It should be like this…

skuid.ui.fieldRenderersR‘PICKLIST’]field.mode;


Thank you very much Zach !

However, when I added field.options.type = ‘REFPICK’; it is giving me original link but not the intended link (‘href’,‘/apex/TeamMemberView?id=’ + targetFieldId)). 

-Jnanendra


Hi Zach, I tried your approach and tried to solve problem by rewriting the snippet as :


var field = arguments[0],    value = skuid.utils.decodeHTML(argumentst1]),
    $ = skuid.$,
    displayType = field.metadata.displaytype,
    targetFieldId;
if (displayType === ‘STRING’ || displayType === ‘TEXT’) {
    // We assume that this is the Name field value,
    // otherwise there wouldn’t be a link
    targetFieldId = field.row.Id;
} else if (displayType === ‘REFERENCE’) {
    targetFieldId = value;
}
skuid.ui.fieldRenderers}field.metadata.displaytype]field.mode;

// in edit mode render the reference field as pick list       
if(field.mode === ‘edit’) {
        field.options.type = ‘REFPICK’;
        skuid.ui.fieldRenderersFfield.metadata.displaytype]kfield.mode](field, value);

    }

if (field.mode !== ‘edit’) {
    var link = field.element.find(‘a’);
    if (link.length) {
        link.attr(‘href’,‘/apex/TeamMemberView?id=’ + targetFieldId);
    }
}



This code works fine except  I edit the record ( inline edit) and cancel it , the link takes me to original salesforce link (https://ap1.salesforce.com/00590000002Qaqs) instead of 
href’,‘/apex/TeamMemberView?id=’ + targetFieldId

 How could I address this issue  and make it work for the edit and cancel scenario as well?

Thanks!
-Jnanendra