tag:blogger.com,1999:blog-35121136988055687422024-02-19T09:06:34.805-08:00Microsoft Dynamics CRM Technical Help ForumSreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-3512113698805568742.post-34326579235934413092017-06-13T07:14:00.004-07:002017-06-13T07:14:47.543-07:00Querying Entity collection using LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
EntityCollection resulttemp = getContactEntityCollection(erRequest.Id, service);<br />
if (resulttemp != null)<br />
{<br />
List<Entity> listGCRQue = resulttemp.Entities.Where(e => (e.Contains("mms_reason") && ((OptionSetValue)e["OptionsetSchemaname"]).Value == 100000148 || ((OptionSetValue)e["OptionsetSchemaname"]).Value == 100000149 || ((OptionSetValue)e["OptionsetSchemaname"]).Value == 100000150 || ((OptionSetValue)e["OptionsetSchemaname"]).Value == 100000151)).ToList();<br />
List<Entity> listNonGCRQue = resulttemp.Entities.Where(e => (e.Contains("OptionsetSchemaname") && ((OptionSetValue)e["mms_reason"]).Value != 100000148 && ((OptionSetValue)e["OptionsetSchemaname"]).Value != 100000149 && ((OptionSetValue)e["OptionsetSchemaname"]).Value != 100000150 && ((OptionSetValue)e["OptionsetSchemaname"]).Value != 100000151)).ToList();<br />
<br />
if ((listGCRQue.Count > 0) || (listGCRQue.Count == 0 && listNonGCRQue.Count != 0 && (reasonValue == 100000148 || reasonValue == 100000149 || reasonValue == 100000150 || reasonValue == 100000151)))<br />
{<br />
throw new InvalidPluginExecutionException(OperationStatus.Canceled, "Error message");<br />
}<br />
}<br />
<br />
<br />
public EntityCollection getContactEntityCollection(Guid reqId, IOrganizationService service)<br />
{<br />
string fetchXml = "";<br />
fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +<br />
"<entity name='incident'>" + <br />
"<attribute name='OptionsetSchemaname' />" +<br />
"<attribute name='incidentid' />" +<br />
"<filter type='and'>" +<br />
"<condition attribute='mms_requestid' operator='eq' value='" + reqId + "' />" +<br />
"</filter>" +<br />
"</entity>" +<br />
"</fetch>";<br />
<br />
EntityCollection resulttemp = service.RetrieveMultiple(new FetchExpression(fetchXml));<br />
if (resulttemp != null && resulttemp.Entities.Count > 0)<br />
return resulttemp;<br />
else<br />
return null;<br />
}</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-32968442953910617912017-06-13T07:06:00.000-07:002017-06-13T07:06:04.707-07:00How to share data b/w plugins<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
he Microsoft Dynamics CRM 2011 platform and the execution pipeline provides the ability to pass data from one plug-in to another through an IPluginExecutionContext property called SharedVariables. This property is a collection of key/value pairs which developers can use to share data between plug-ins which are registered on both the pre and post events.<br />
<br />
<br />
<br /></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9rS5kL5QE8wvepHV2vfZteW3jWqquhnSafC0re2wtLdAr-r4d_VuVTD3Kl5OqGJIMxjdJvhGRRebj_j1wXMHJUIXo1gH9d6Bb41D4j-7KANqS_WAg2n8qKRN8M_e0xy9lX78MSSlrbIKh/s1600/sharedvariables.png" imageanchor="1"><img border="0" data-original-height="260" data-original-width="612" height="136" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9rS5kL5QE8wvepHV2vfZteW3jWqquhnSafC0re2wtLdAr-r4d_VuVTD3Kl5OqGJIMxjdJvhGRRebj_j1wXMHJUIXo1gH9d6Bb41D4j-7KANqS_WAg2n8qKRN8M_e0xy9lX78MSSlrbIKh/s320/sharedvariables.png" width="320" /></a><br />
Here is a simple code snippet which shows shared variables in action. We may perform some data validation on the pre-create stage of an Account and then pass an updateRelated boolean variable to a post-create Account
plug-in which can perform some additional business logic such as asynchronously updating child records of an Account.
Pre-Create Account Plug-in
if (context.InputParameters.ContainsKey("Target") && context.InputParameters["Target"] isEntity)
{
Entity target = context.InputParameters["Target"] as Entity;
if (target != null)
{ // some wacky data validation
string city = target.GetAttributeValue<string>("address1_city") ?? string.Empty;
int numEmployees = target.GetAttributeValue<int>("numberofemployees");
int accountCategory = target.GetAttributeValue<int>("accountcategorycode"); // city is auckland, numEmployees > 100, account category is preferred customer bool updateRelated = city.Equals("Auckland",StringComparison.InvariantCultureIgnoreCase) && numEmployees > 100 && accountCategory == 1; context.SharedVariables.Add("updatedRelated", updateRelated); } } Post-Create Account Plug-in if (context.InputParameters.ContainsKey("Target") && context.InputParameters["Target"] isEntity) { Entity target = context.InputParameters["Target"] as Entity; if (target != null) { if (context.SharedVariables.ContainsKey("updatedRelated")) { bool updateRelated = (bool)context.SharedVariables["updatedRelated"]; if (updateRelated) { // additional logic to update related records of the Account } } } }
That’s all there is to it. This technique lets you build complex plug-ins and pass data between plug-ins without having to set hidden fields on entities.</int></int></string></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-77078570848911593022016-12-06T21:56:00.002-08:002016-12-06T21:56:36.230-08:00Hide Areas and Sub Areas in the Site Map using Security Roles in Dynamics CRM (Privilege tag)<div dir="ltr" style="text-align: left;" trbidi="on">
<header class="entry-header" style="background-color: white; color: #373737; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 15px; margin: 0px auto; width: 584.263px;"><h1 class="entry-title" style="border: 0px; clear: both; color: black; font-family: inherit; font-size: 36px; font-style: inherit; line-height: 48px; margin: 0px; outline: 0px; padding: 15px 0px 0.3em; vertical-align: baseline;">
<u>Hide Areas & Sub Areas in the SiteMap using Security Roles in Dynamics CRM (Privilege tag)</u></h1>
<div class="entry-meta" style="border: 0px; clear: both; color: #666666; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; left: 0px; line-height: 18px; margin: 0px; outline: 0px; padding: 0px; position: absolute; top: 0px; vertical-align: baseline;">
<br /></div>
</header><div class="entry-content" style="background-color: white; border: 0px; color: #373737; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 15px; margin: 0px auto; outline: 0px; padding: 1.625em 0px 0px; vertical-align: baseline; width: 584.263px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
If you need to show or hide a sub area in your SiteMap based on access control security roles, you can easily do this using the Privilege tag in the SiteMap as follows:</div>
<blockquote style="border: 0px; font-family: Georgia, "Bitstream Charter", serif; font-style: italic; margin: 0px 3em; outline: 0px; padding: 0px; quotes: "" ""; vertical-align: baseline;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<SubArea Id=”crm_myentity” Entity=”crm_myentity”><br /><Privilege Entity=”crm_myentity” Privilege=”Read” /><br /></SubArea></div>
</blockquote>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
Based on the above, this sub area will only be shown to users who have security roles with read privilege of the custom entity: crm_myentity.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
You can add the privilege tag above to any sub area and the entity in the privilege tag can be any entity and doesn’t have to be the same one as the sub area. For example, the following is also applicable:</div>
<blockquote style="border: 0px; font-family: Georgia, "Bitstream Charter", serif; font-style: italic; margin: 0px 3em; outline: 0px; padding: 0px; quotes: "" ""; vertical-align: baseline;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<SubArea Id=”contact” Entity=”contact” Title=”Contacts”><br /><Privilege Entity=”crm_myentity” Privilege=”Read” /><br /></SubArea></div>
</blockquote>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
This will hide the contact sub area for users without the read privilege for the entity crm_myentity. You can mix and match as much as you want to show and hide any sub area in the sitemap based on any entity you require whether they are customisable/system or custom entities.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
As for hiding and controling access to a whole area in the sitemap such as Sales, Marketing or Service (site map section), you will need to set the privilege tag to every sub area inside this area.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
So for example, if you want to hide the whole of the Sales Area for specific users, you need to add the “<privilege />” tag to every sub area in the Sales Area. What you can also do, is create a custom entity specifically for setting the security on the SiteMap. The following example will hide the Sales (or marketing or service) area for all users who do not have a security role with read access to the custom entity crm_SiteMapPrivilege:</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<!–Sales Area–></div>
<blockquote style="border: 0px; font-family: Georgia, "Bitstream Charter", serif; font-style: italic; margin: 0px 3em; outline: 0px; padding: 0px; quotes: "" ""; vertical-align: baseline;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<Area Id=”SFA” ResourceId=”Area_Sales” Icon=”/_imgs/sales_24x24.gif” DescriptionResourceId=”Sales_Description”><br /><Group Id=”SFA”><br /><SubArea Id=”nav_leads” Entity=”lead”><br /><Privilege Entity=”crm_myentity” Privilege=”Read” /><br /></SubArea><br /><SubArea Id=”nav_oppts” Entity=”opportunity”><br /><Privilege Entity=”crm_myentity” Privilege=”Read” /><br /></SubArea><br />….<br /></Group><br /></Area></div>
</blockquote>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
What you can then do is that, you make every sub area in the Sales area requiring the read privilege of SiteMapPrivilege entity, every sub area under the Marketing area can then have the Write privilege and every sub area under the Service area can have the Create privilege of the crm_SiteMapPrivilege entity. So similar to how the Sales area has read as per the previous example, the Marketing and Service areas can look like this:</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<!–Marketing Area–></div>
<blockquote style="border: 0px; font-family: Georgia, "Bitstream Charter", serif; font-style: italic; margin: 0px 3em; outline: 0px; padding: 0px; quotes: "" ""; vertical-align: baseline;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<Area Id=”MA” ResourceId=”Area_Marketing” Icon=”/_imgs/marketing_24x24.gif” escriptionResourceId=”Marketing_Description”><br /><Group Id=”MA”><br /><SubArea Id=”nav_leads” Entity=”lead”><br /><Privilege Entity=”crm_myentity” Privilege=”Write” /><br /></SubArea><br /><SubArea Id=”nav_accts” Entity=”account”><br /><Privilege Entity=”crm_myentity” Privilege=”Write” /><br /></SubArea><br />…..</div>
</blockquote>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<!–Service Area–></div>
<blockquote style="border: 0px; font-family: Georgia, "Bitstream Charter", serif; font-style: italic; margin: 0px 3em; outline: 0px; padding: 0px; quotes: "" ""; vertical-align: baseline;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<Area Id=”CS” ResourceId=”Area_Service” Icon=”/_imgs/services_24x24.gif” DescriptionResourceId=”Customer_Service_Description”><br /><Group Id=”CS”><br /><SubArea Id=”nav_apptbook”><br /><Privilege Entity=”activitypointer” Privilege=”Read” /><br /><Privilege Entity=”service” Privilege=”Create” /><br /></SubArea><br /><SubArea Id=”nav_cases” Entity=”incident><br /><Privilege Entity=”service” Privilege=”Create” /><br /></SubArea><br />…..</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
</blockquote>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
Hence, based on the above 3 examples (Sales, Marketing, Service), you will need to make sure that users who should see the Sales Area has a security role with the read privilege of our custom entity (crm_SiteMapPrivilege), users who should see the Marketing area must have a security role with the Write privilege of crm_SiteMapPrivilege and Create privilege for Service.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
The same applies for any additional Areas that you creates. So if you have added a new custom Area in your SiteMap, you should then use another privilege (append, appendto, etc) for every sub area under your new custom Area in the Site Map to show and hide this area based on your chosen privilege.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
You can either manually amend your users security roles to add the privilege (read, write, etc..) or alternatively, a much better way of doing this is to create a new security role for each area. So what I have done is I created the following security roles: Access to Sales Area Access to Marketing Area Access to Service Area Access to MyCustom Area</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
In each security role, I only set the privilege for my custom entity crm_sitemapprivilege as follows:</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
For Security role: Access to Sales Area, set “Read” on crm_sitemapprivilege For Security role: Access to Marketing Area, set “Write” on crm_sitemapprivilege For Security role: Access to Service Area, set “Create” on crm_sitemapprivilege For Security role: Access to MyCustom Area, set “Append” on crm_sitemapprivilege</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
Once I’ve done that, I add those security roles to the users based on what they need to see. So for example: User1, need to see sales area, assign security role: Access to Sales Area. User2, need to see marketing area, assign security role: Access to Marketing Area. and so on,</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
you get the drill.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
Last thing to mention is the possible privilege values that you can use. These can be:</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
All AllowQuickCampaign Append AppendTo Assign Create Delete Read Share Write</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
you can also use a combination of those values such as: “Read,Write” or “Read,Write,Create” and so on.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
so your privilege tag will look something like this:</div>
<blockquote style="border: 0px; font-family: Georgia, "Bitstream Charter", serif; font-style: italic; margin: 0px 3em; outline: 0px; padding: 0px; quotes: "" ""; vertical-align: baseline;">
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
<Privilege Entity=”crm_sitemapprivilege” Privilege=”Read,Write” /><br /><!– OR –><br /><Privilege Entity=”crm_sitemapprivilege” Privilege=”Read,Write,Share,Write,Append” /></div>
</blockquote>
<div style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin-bottom: 1.625em; outline: 0px; padding: 0px; vertical-align: baseline;">
The advantage of using combinations is that it will allow you to do this for as many Areas as you could ever need.</div>
</div>
</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-58665732232903925132016-12-06T21:43:00.004-08:002016-12-06T21:43:48.631-08:00Sitemap Customization Helpful URLs<div dir="ltr" style="text-align: left;" trbidi="on">
Sitemap Customization Helpful URLs<br />
<br />
1. http://www.mohamedmostafa.co.uk/blog/2012/11/13/hide-areas-sub-areas-in-the-sitemap-using-security-roles-in-dynamics-crm-privilege-tag/<br />
<br />
2. https://dipankarbhattacharya.com/2014/05/06/hiding-sitemap-components-based-on-user-profile/<br />
<br />
3. https://saikrishnayadav.blogspot.in/2012/10/how-to-hide-marketing-module-for-some.html#comment-form</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-44609814341446218992014-07-30T05:21:00.000-07:002014-07-30T05:21:29.385-07:00MSCRM Important Technical Links<div dir="ltr" style="text-align: left;" trbidi="on">
http://balarajann.blogspot.in/2013/03/microsoft-dynamics-crm-2011-javascript.html<br />
<br />
http://guruprasadcrm.blogspot.in/2011/11/how-to-debug-crm-2011-online-plugin.html<br />
<br />
http://msdynamicscrmblog.wordpress.com/2013/03/10/get-login-user-role-names-in-javascript-in-dynamics-crm-2011/<br />
<br />
http://rajeevpentyala.wordpress.com/2011/07/23/useful-crm-2011-jscript-syntaxes/<br />
<br />
http://blog.lulutech.com/?p=498<br />
<br />
<h1 class="title" style="color: black; font-family: 'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1.167; margin-top: 0px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<u><b><span style="font-size: x-small;">OData system query options using the OData endpoint</span></b></u></h1>
http://msdn.microsoft.com/en-in/library/gg309461.aspx<br />
<br />
http://garethtuckercrm.com/2011/03/16/jscript-reference-for-microsoft-dynamics-crm-2011/</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-74782024356296409412014-07-29T22:14:00.002-07:002014-07-29T22:14:34.378-07:00Get and Set lookup value using javascript in Dynamics CRM 2013<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 class="title entry-title" itemprop="name">
<a href="http://balarajann.blogspot.com/2013/01/get-and-set-lookup-value-using.html" itemprop="url" rel="bookmark">
Get and Set lookup value using javascript in Dynamics CRM 2013 </a>
</h1>
In this article , I am going to explain how to set and get CRM lookup attribute value using javascript
<br />
<br />
<b><i><u><span style="color: #e69138;">Get a lookup value</span></u></i></b><br />
var lookup = new Array();<br />
lookup = Xrm.Page.getAttribute("attributename").getValue();<br />
if (lookup != null) {<br />
var name = lookup[0].name;<br />
var id = lookup[0].id;<br />
var entityType = lookup[0].entityType;<br />
}<br />
<br />
<b><i><u><span style="color: #e69138;">Set a lookup value</span></u></i></b><br />
var lookup = new Array();<br />
lookup[0] = new Object();<br />
lookup[0].id = recorid;<br />
lookup[0].name = recordname;<br />
lookup[0].entityType = entityname;<br />
Xrm.Page.getAttribute("attributename").setValue(lookup);<br />
<br />
<b><i><u><span style="color: #e69138;">Alternate method to set lookup value</span></u></i></b><br />
Xrm.Page.getAttribute("attributename").setValue([{ id: recorid, name: recordname, entityType: entityname}]);<br />
</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-20506737746396918612014-07-23T06:46:00.000-07:002014-07-23T06:48:19.741-07:00Get Login User Role name in JavaScript using OData<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="container">
<div class="line number1 index0 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript comments">//Check login User has 'System Administrator' role</code></span></span></div>
<div class="line number2 index1 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript keyword">function</code> <code class="jscript plain">CheckUserRole() {</code></span></span></div>
<div class="line number3 index2 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">var</code> <code class="jscript plain">currentUserRoles = Xrm.Page.context.getUserRoles();</code></span></span></div>
<div class="line number4 index3 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">for</code> <code class="jscript plain">(</code><code class="jscript keyword">var</code> <code class="jscript plain">i = 0; i < currentUserRoles.length; i++) {</code></span></span></div>
<div class="line number5 index4 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">var</code> <code class="jscript plain">userRoleId = currentUserRoles[i];</code></span></span></div>
<div class="line number6 index5 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">var</code> <code class="jscript plain">userRoleName = GetRoleName(userRoleId);</code></span></span></div>
<div class="line number7 index6 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">if</code> <code class="jscript plain">(userRoleName == </code><code class="jscript string">"System Administrator"</code><code class="jscript plain">) {</code></span></span></div>
<div class="line number8 index7 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">return</code> <code class="jscript keyword">true</code><code class="jscript plain">;</code></span></span></div>
<div class="line number9 index8 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">}</code></span></span></div>
<div class="line number10 index9 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">}</code></span></span></div>
<div class="line number11 index10 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">return</code> <code class="jscript keyword">false</code><code class="jscript plain">;</code></span></span></div>
<div class="line number12 index11 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript plain">}</code></span></span></div>
<div class="line number13 index12 alt2">
</div>
<div class="line number14 index13 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript comments">//Get Rolename based on RoleId</code></span></span></div>
<div class="line number15 index14 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript keyword">function</code> <code class="jscript plain">GetRoleName(roleId) {</code></span></span></div>
<div class="line number16 index15 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript comments">//var serverUrl = Xrm.Page.context.getServerUrl();</code></span></span></div>
<div class="line number17 index16 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">var</code> <code class="jscript plain">serverUrl = location.protocol + </code><code class="jscript string">"//"</code> <code class="jscript plain">+ location.host + </code><code class="jscript string">"/"</code> <code class="jscript plain">+ Xrm.Page.context.getOrgUniqueName();</code></span></span></div>
<div class="line number18 index17 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">var</code> <code class="jscript plain">odataSelect = serverUrl + </code><code class="jscript string">"/XRMServices/2011/OrganizationData.svc"</code> <code class="jscript plain">+ </code><code class="jscript string">"/"</code> <code class="jscript plain">+ </code><code class="jscript string">"RoleSet?$filter=RoleId eq guid'"</code> <code class="jscript plain">+ roleId + </code><code class="jscript string">"'"</code><code class="jscript plain">;</code></span></span></div>
<div class="line number19 index18 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">var</code> <code class="jscript plain">roleName = </code><code class="jscript keyword">null</code><code class="jscript plain">;</code></span></span></div>
<div class="line number20 index19 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">$.ajax(</code></span></span></div>
<div class="line number21 index20 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">{</code></span></span></div>
<div class="line number22 index21 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">type: </code><code class="jscript string">"GET"</code><code class="jscript plain">,</code></span></span></div>
<div class="line number23 index22 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">async: </code><code class="jscript keyword">false</code><code class="jscript plain">,</code></span></span></div>
<div class="line number24 index23 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">contentType: </code><code class="jscript string">"application/json; charset=utf-8"</code><code class="jscript plain">,</code></span></span></div>
<div class="line number25 index24 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">datatype: </code><code class="jscript string">"json"</code><code class="jscript plain">,</code></span></span></div>
<div class="line number26 index25 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">url: odataSelect,</code></span></span></div>
<div class="line number27 index26 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">beforeSend: </code><code class="jscript keyword">function</code> <code class="jscript plain">(XMLHttpRequest) { XMLHttpRequest.setRequestHeader(</code><code class="jscript string">"Accept"</code><code class="jscript plain">, </code><code class="jscript string">"application/json"</code><code class="jscript plain">); },</code></span></span></div>
<div class="line number28 index27 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">success: </code><code class="jscript keyword">function</code> <code class="jscript plain">(data, textStatus, XmlHttpRequest) {</code></span></span></div>
<div class="line number29 index28 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">roleName = data.d.results[0].Name;</code></span></span></div>
<div class="line number30 index29 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">},</code></span></span></div>
<div class="line number31 index30 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">error: </code><code class="jscript keyword">function</code> <code class="jscript plain">(XmlHttpRequest, textStatus, errorThrown) { alert(</code><code class="jscript string">'OData Select Failed: '</code> <code class="jscript plain">+ textStatus + errorThrown + odataSelect); }</code></span></span></div>
<div class="line number32 index31 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">}</code></span></span></div>
<div class="line number33 index32 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript plain">);</code></span></span></div>
<div class="line number34 index33 alt1">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript spaces"> </code><code class="jscript keyword">return</code> <code class="jscript plain">roleName;</code></span></span></div>
<div class="line number35 index34 alt2">
<span style="font-family: Verdana,sans-serif;"><span style="font-size: small;"><code class="jscript plain">}</code></span></span></div>
</div>
</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-44692266277885072182014-07-23T05:27:00.003-07:002014-07-23T05:27:44.607-07:00Set Default Currency<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
function setDefaultCurrency() {<br />
<span style="white-space: pre;"></span>var lookup = new Array();<br />
<span style="white-space: pre;"></span>lookup[0] = new Object();<br />
<span style="white-space: pre;"></span>lookup[0].id = '{0929D216-DDE7-E311-93EF-74D43599CE45}'; // your currency ID<br />
<span style="white-space: pre;"></span>lookup[0].name = 'Rupee';// Your currency name<br />
<span style="white-space: pre;"></span>lookup[0].entityType = 'transactioncurrency';<br />
<span style="white-space: pre;"></span>Xrm.Page.getAttribute('transactioncurrencyid').setValue(lookup);<br />
}</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-13518653467407046902014-07-23T02:36:00.000-07:002014-07-23T02:36:16.119-07:00Loop through Subgrid records<div dir="ltr" style="text-align: left;" trbidi="on">
function RetrieveSubGridRecords() {<br /><br /> if (document.getElementById("SubgridId")) {<br /><br /> var grid = document.getElementById("SubgridId").control;<br /> var totalBilled = 0;<br /> var totalUnBilled =0;<br /> for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)<br /> {<br /> <br /> if(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[7].outerText.indexOf("Yes") >= 0)<br /> {<br /> var numvalue = grid.GetRecordsFromInnerGrid()[rowNo][3].cells[6].outerText.replace(new RegExp(',', 'g'), '');<br /> alert(numvalue);<br /> totalBilled = totalBilled + parseFloat(numvalue);<br /> alert("yes"+totalBilled);<br /> }<br /> else<br /> {<br /> var numvalue = grid.GetRecordsFromInnerGrid()[rowNo][3].cells[6].outerText.replace(new RegExp(',', 'g'), '');<br /> alert(numvalue);<br /> totalUnBilled = totalUnBilled + parseFloat(numvalue);<br /> alert("no"+totalUnBilled);<br /> }<br /> <br /> }<br /> Xrm.Page.getAttribute("new_totalbilledamount").setValue(totalBilled);<br /> Xrm.Page.getAttribute("new_totalunbilledamt").setValue(totalUnBilled); <br /><br /> }<br /><br /> else {<br /><br /> setTimeout("RetrieveSubGridRecords();", 2500);<br /><br /> }<br /><br /><br />}</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-32790059568297606842014-07-23T02:31:00.001-07:002014-07-23T02:31:04.618-07:00Bind look up field text to a attribute<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;">function addtitle() {<br /> var issuetype = Xrm.Page.getAttribute("ccs_requesttype").getValue();<br /> if (issuetype == null) {<br /> return false;<br /> }<br /> var issuetypename = issuetype[0].name;<br /> Xrm.Page.getAttribute("title").setValue(issuetypename);<br />}</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-91466507893864667652014-07-23T02:10:00.000-07:002014-07-23T02:10:13.661-07:00Get Logged in User Teams and Get Team details by TeamId<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;">function getUserTeams() {<br /> var userId = Xrm.Page.context.getUserId().substr(1, 36);<br /> var serverUrl = "/" + Xrm.Page.context.getOrgUniqueName();<br /> var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";<br /> oDataEndpointUrl += "TeamMembershipSet?$filter=SystemUserId eq guid' " + userId + " '";<br /> var service = GetRequestObject();<br /> if (service != null) {<br /> service.open("GET", oDataEndpointUrl, false);<br /> service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");<br /> service.setRequestHeader("Accept", "application/json,text/javascript, */*");<br /> service.send(null);<br /> var requestResults = eval('(' + service.responseText + ')').d;<br /> if (requestResults != null && requestResults.results.length > 0) {<br /> return requestResults.results;<br /> }<br /> }<br />}</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">function getUserTeamName(teamid) {<br /> var serverUrl = "/" + Xrm.Page.context.getOrgUniqueName();<br /> var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";<br /> oDataEndpointUrl += "TeamSet?$select=Name,TeamId&$filter=TeamId eq guid'" + teamid + "'";<br /> var service = GetRequestObject();<br /> if (service != null) {<br /> service.open("GET", oDataEndpointUrl, false);<br /> service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");<br /> service.setRequestHeader("Accept", "application/json,text/javascript, */*");<br /> service.send(null);<br /> var requestResults = eval('(' + service.responseText + ')').d;<br /> if (requestResults != null && requestResults.results.length > 0) {<br /> return requestResults.results;<br /> }<br /> }<br />}</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">function GetRequestObject() {<br /> if (window.XMLHttpRequest) {<br /> return new window.XMLHttpRequest;<br /> } else {<br /> try {<br /> return new ActiveXObject("MSXML2.XMLHTTP.3.0");<br /> } catch (ex) {<br /> return null;<br /> }<br /> }<br />}</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-43592901563354626762014-07-23T02:04:00.005-07:002014-07-23T02:04:39.046-07:00Make attribute readonly<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<u><b>Make Attribute readonly </b></u></h2>
<br />
Xrm.Page.ui.controls.get("AttributeName").setDisabled(true);</div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-90738781356287452462013-11-26T04:44:00.002-08:002013-11-26T04:45:35.272-08:00MSCRM 2011 : Enabling and Disabling the Attribute using Java script<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><strong><u>MSCRM 2011 : Enabling and Disabling the Attribute using Java script</u></strong></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><strong>To Disable</strong></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Xrm.Page.ui.controls.get(<span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"new_customer"</span></span></span>).setDisabled(<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">true</span></span></span>);</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><strong>To Enable</strong></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Xrm.Page.ui.controls.get(<span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"new_customer"</span></span></span>).setDisabled(<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">false</span></span></span>);</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Hope this will help :)</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Best Regards,</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Sreenath</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-55017328747476574902013-11-26T04:40:00.000-08:002013-11-26T04:40:32.169-08:00MSCRM : Checking the Checkbox is checked or not using Java script<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> <strong><u>MSCRM 2011 : Checking the Checkbox is checked or not using Java script</u></strong></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> useexistingcheckbox = <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"checkboxAttributeName"</span></span></span>;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> <span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> ckeckboxControl = Xrm.Page.ui.controls.get(useexistingcheckbox);</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> <span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> ckeckboxControlValue = ckeckboxControl.getAttribute().getValue();</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> <span style="color: blue;"><span style="color: blue;"><span style="color: blue;">if</span></span></span> (ckeckboxControlValue == <span style="color: blue;"><span style="color: blue;"><span style="color: blue;">true</span></span></span>) </span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">{</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> //Code</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">}</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">else</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">{</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> //Code</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">}</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Hope This will Help :)</span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: Arial;">Best Regards,</span><br />
<span style="font-family: Arial;">Sreenath</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-53809741981249488072013-11-25T23:47:00.000-08:002013-11-25T23:47:37.991-08:00MSCRM : Change background color of Attribute using Javascript<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><strong><u>MSCRM 2011: Change background color of Attribute using JavaScript</u></strong></span><br />
<span style="font-family: Arial;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Use the following code:</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">document.getElementById(<span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"AttributeName"</span></span></span>).style.backgroundColor = <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"#FFFF99"</span></span></span>;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Hope this will help :)</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Best Regards,</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Sreenath</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-26149861650782597222013-11-25T23:15:00.000-08:002013-11-25T23:15:11.323-08:00MSCRM : Setting value for a Attribute using Java Script<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<u><span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">MSCRM 2011 : Setting value for a Attribute using Java Script</span></u></h3>
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Use the following code.</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Xrm.Page.getAttribute("AttributeName").setValue("AttributeValue");</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Hope this will Help :)</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Best Regards,</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Sreenath M</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-84763934228446674822013-11-25T22:40:00.000-08:002013-11-25T23:15:56.495-08:00MSCRM : Filtering Lookups using Javascript<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: orange;">MSCRM 2011: Filtering Cities based on State</span></span></h3>
<span style="color: blue; font-size: x-small;"><span style="color: blue; font-size: x-small;"><span style="color: blue; font-family: "Helvetica Neue", Arial, Helvetica, sans-serif; font-size: x-small;"></span></span></span><br />
<span style="color: blue; font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Use the following code to filter and change the Entity names according to your requirement.</span><br />
<span style="color: blue; font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><span style="color: blue;"><span style="color: blue;"><span style="color: blue;">function</span></span></span> onstateChange() </span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">{</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> stateAttr = Xrm.Page.data.entity.attributes.get(<span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"new_state"</span></span></span>);</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">if</span></span></span> (stateAttr.getValue() != <span style="color: blue;"><span style="color: blue;"><span style="color: blue;">null</span></span></span>) </span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"> {</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> stateID = stateAttr.getValue()[0].id;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> viewID = stateID;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> viewDisplayName = <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"Filtered by state - "</span></span></span> + stateAttr.getValue()[0].name;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> viewIsDefault = <span style="color: blue;"><span style="color: blue;"><span style="color: blue;">true</span></span></span>;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> fetchXml = <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">'<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="new_city"><attribute name="new_cityid"/><attribute name="new_name"/><attribute name="createdon"/><order attribute="new_name" descending="false"/><filter type="and"><condition attribute="new_state" operator="eq" value="'</span></span></span> + stateID + <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">'"/></filter></entity></fetch>'</span></span></span>;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> layoutXml = <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">'<grid name="resultset" object="10001" jump="new_name" select="1" icon="1" preview="1"><row name="result" id="new_cityid"><cell name="new_name" width="300" /><cell name="createdon" width="125"/></row></grid>'</span></span></span>;</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
<span style="color: blue;"><span style="color: blue;"><span style="color: blue;">var</span></span></span> phaseControl = Xrm.Page.ui.controls.get(<span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"new_city"</span></span></span>);</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
phaseControl.addCustomView(viewID, <span style="color: maroon;"><span style="color: maroon;"><span style="color: maroon;">"new_city"</span></span></span>, viewDisplayName, fetchXml, layoutXml, viewIsDefault);</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">
}<br />
}<br />
<br />
Hope this will help :)<br />
<br />
Best Regards,<br />
Sreenath</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0tag:blogger.com,1999:blog-3512113698805568742.post-29863941180174187282013-11-25T22:23:00.003-08:002013-11-25T23:17:25.672-08:00Making Entity Attribute as required through Java Script<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"><strong><u>CRM 2011: In Java Script Web resource please add the below code.</u></strong></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Xrm.Page.getAttribute("AttributeName").setRequiredLevel("required");</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Hope this Will Help :)</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Regards,</span><br />
<span style="font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;">Sreenath</span></div>
Sreenath Medikurthihttp://www.blogger.com/profile/08018077118231645135noreply@blogger.com0