Crm 2011 - How to set a default form depending on attribute value (without using Javascript)? -


i have little requirement making me crazy: have 8 different forms contact entity. have pick list 8 options. idea based on option selected open contact record showing default particular form without using javascript in order avoid performance problems (each record has loaded twice). example:

forms:
form 1
form 2
form 3

pick list values - default form:

form 1
form 2
form 3

if form 3(pick list value) selected then, next time open record, form 3 should displayed default.

if form 1(pick list value) selected then, next time open record, form 1 should displayed default.

i've trayed registering plugin @ systemform entity, in retrievefilteredforms message, updating userentityuisettings table , i've been able set "default" displayed every time records opened regardless last opened form.

i've trayed registering plugin @ contact entity, in retrieve message, updating userentityuisettings table found crm consults table once if there no attribute updated, following times crm take the default form open value cache.

this old question since it's coming in searches problem wanted add solution.

we use dynamics crm 2013. knowledge, later versions of 2011 support technique.

the form displayed when entity opened determined few things - default form, security roles , fallback settings form , last form used current user entity. had similar problem asker wanted different account form displayed based on value of form. tired of constant reload/refresh javascript techniques subject to.

i found blog posts (in particular one: http://gonzaloruizcrm.blogspot.com/2014/11/avoiding-form-reload-when-switching-crm.html) mentioned possible write plugin retrieve of entity allows read out value (lastviewedformxml) userentityuisettings stores form last used. if it's not form want, can write in desired value. avoids javascript form refreshing.

i had modify code samples found work, i'm happy results. need generate entity class using crmsvcutil , include in project. can form guids url of form editor.

using system; using system.collections.objectmodel; using system.globalization; using system.linq; using system.servicemodel; using system.servicemodel.description;  using microsoft.xrm.sdk; using microsoft.xrm.sdk.messages; using microsoft.xrm.sdk.query; using microsoft.xrm.sdk.client;  namespace crm.plugin.accountformswitcher {     public class plugin : iplugin     {         public enum accounttype         {             customer =  100000000,             vendor =     100000001,             partner = 100000002,             other =    100000003         }          public const string customeraccountformid = "00000000-e53c-4df4-bc99-93856edd168c";         public const string vendoraccountformid = "00000000-e49e-4197-ab5e-f353ef0e806e";         public const string partneraccountformid = "00000000-b8c6-4e2b-b84e-729aa11abe61";         public const string genericaccountformid = "00000000-8f42-454e-8e2a-f8196b0419af";          public const string accounttypeattributename = "cf_accounttype";          public void execute(iserviceprovider serviceprovider)         {             if (serviceprovider == null)             {                 throw new argumentnullexception("serviceprovider");             }              // obtain execution context service provider.             ipluginexecutioncontext context = (ipluginexecutioncontext)serviceprovider.getservice(typeof(ipluginexecutioncontext));              itracingservice tracingservice = (itracingservice)serviceprovider.getservice(typeof(itracingservice));              iorganizationservicefactory servicefactory = (iorganizationservicefactory)serviceprovider.getservice(typeof(iorganizationservicefactory));             iorganizationservice service = servicefactory.createorganizationservice(context.userid);              var plugincontext = (ipluginexecutioncontext)context;             if (plugincontext.stage == 20) //pre-operation stage             {                 var columns = (columnset)plugincontext.inputparameters["columnset"];                 if (!columns.columns.contains(accounttypeattributename))                     columns.addcolumn(accounttypeattributename);             }             else if (plugincontext.stage == 40) //post-operation stage             {                 entityreference currententity = (entityreference)context.inputparameters["target"];                 if (currententity == null)                     return;                  var query = new queryexpression(account.entitylogicalname);                 query.criteria.addcondition("accountid", conditionoperator.equal, currententity.id);                 query.columnset = new columnset(accounttypeattributename);                 var accounts = service.retrievemultiple(query).entities;                 account currentaccount = (account)accounts[0];                  setform(currentaccount, service, context.userid);             }         }          private void setform(account account, iorganizationservice service, guid userid)         {             var query = new queryexpression(userentityuisettings.entitylogicalname);             query.criteria.addcondition("ownerid", conditionoperator.equal, userid);             query.criteria.addcondition("objecttypecode", conditionoperator.equal, account.entitytypecode);             query.columnset = new columnset("lastviewedformxml");             var settings = service.retrievemultiple(query).entities;              // users such system have no userentityuisettings, skip.             if (settings == null || settings.count != 1 || account.cf_accounttype == null) return;              var setting = settings[0].toentity<userentityuisettings>();             string formtouse;             switch ((accounttype)account.cf_accounttype.value)             {                 case accounttype.customer:                     formtouse = string.format("<mruform><form type=\"main\" id=\"{0}\" /></mruform>", customeraccountformid);                     break;                 case accounttype.vendor:                     formtouse = string.format("<mruform><form type=\"main\" id=\"{0}\" /></mruform>", vendoraccountformid);                     break;                 case accounttype.partner:                     formtouse = string.format("<mruform><form type=\"main\" id=\"{0}\" /></mruform>", partneraccountformid);                     break;                 case accounttype.other:                     formtouse = string.format("<mruform><form type=\"main\" id=\"{0}\" /></mruform>", genericaccountformid);                     break;                 default:                     formtouse = string.format("<mruform><form type=\"main\" id=\"{0}\" /></mruform>", genericaccountformid);                     return;             }              // update if last viewed form not 1 required given opportunity type             if (!formtouse.equals(setting.lastviewedformxml, stringcomparison.invariantcultureignorecase))             {                 var s = new userentityuisettings { id = setting.id, lastviewedformxml = formtouse };                 service.update(s);             }         }     } } 

and address asker's issue consulting userentityuisettings once, i'm not sure why that's happening. why not use javascript change form when triggering attribute changed? , haven't ran problems plugin not displaying desired for.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -