Render component based on users access to a field

To extend the thought here, here’s a snippet to evaluate if a user has access to query an object for using on rendering logic.  This is handy when you have tabs that have page includes in them where you can disable the tab if the underlying include would be inaccessible.  For example, on record detail pages, we have a tabsets to keep the related lists organized and each of these are their own page so we can reuse related lists on many pages. 

The other benefit of this approach is that you don’t need knowledge of the specific skuid Model name.  With page includes, you have to maintain uniqueness of model names so you don’t run into conflicts with your models, which implies a lot of model names to keep track of in snippets.  Moving the snippet logic to the general sObject means only one snippet per object.  Ideally It would be nice to pass the SObject name as a parameter into the snippet from the pagebuilder so there’s only one snippet, but we’re not there yet with snippet parameters.


if(skuid.utils.getAPIDescribeSObject(‘Account’) !== null)
    { 
        if( skuid.utils.getAPIDescribeSObject(‘Account’).queryable == ‘true’ ) 
        {
            return true;
        }
    }
else{
    return false;
}


Likewise, you could disable a new record button if the user doesn’t have permission to crate a target object record:

if(skuid.utils.getAPIDescribeSObject(‘Account’) !== null)
    { 
        if( skuid.utils.getAPIDescribeSObject(‘Account’).createable == ‘true’ ) 
        {
            return true;
        }
    }
else{
    return false;
}


A couple details of interest.  Unlike the skuid.model API, the values in skuid.utils.getAPIDescribeSObject return as a string, which is why the return is wrapped in the if statement.  Also, there’s a null check, which handles script errors if the user has no access to the object.