Monday, May 9, 2016

Filter Activity lookup MSCRM Javascript

Hi All,

Please find the below JS code to filter Lookup Types

In my below Code am filtering requiredattendees, Call the below script in onload function

var lookuptypeIcons = "/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif";
var lookuptypenames = "contact:2:Contact,systemuser:8:User";
var lookuptypes = "2,8";

if (Xrm.Page.getAttribute("requiredattendees") != null) {
                $("#requiredattendees").focus(function () {
                    var toLookUp = $("img[attrName='requiredattendees']");
                    lookuptypes = "2,8";
                    if (toLookUp.length > 0) {
                        toLookUp[0].setAttribute("lookuptypenames", lookuptypenames);
                        toLookUp[0].setAttribute("lookuptypes", lookuptypes);
                        toLookUp[0].setAttribute("lookuptypeIcons", lookuptypeIcons);
                        toLookUp[0].setAttribute("createpermissiondictionary", "contact:true,systemuser:true");
                        toLookUp[0].setAttribute("DefaultViewId", "5DA08E4B-4493-E111-BEF2-00155DC87C59");
                        toLookUp[0].setAttribute("defaulttype", 2);
                    }
                });

            }

Impersonate User in MSCRM 2011/13/15/16

Hi All,

Please find the below c# code to impersonate the user in MSCRM


EntityReference callingUser = new EntityReference
                {
                    LogicalName = "systemuser",
                    Id = {Impersonation User GUID}
                };
OrganizationServiceProxy serviceProxy = (OrganizationServiceProxy)service;
serviceProxy.CallerId = callingUser.Id;


Replace {Impersonation User GUID} with Guid of User to make the Plugin to run as Passing User.

Thursday, May 5, 2016

Convert Text field to URL Field MSCRM 2013/2015/2016

Hi All,

Please find the Below code to Convert Text field to URL Field.

In My case, if user selects a look up value, In onsave operation am saving the value as to the text field as AccountName*AccountnameGuid (initially make the Lookup field enable and make the text field disable)

Once the save operation done. In onload make the Lookup field disable and show the Custom Text to Url Field.

Copy paste the below code and pass the value to "fieldname" to make the value display properly.

After onsave take field should save like below format




After onload the text field will display like below URL Field



function onload(){
converttexttoURL("fieldname");
}

 
function onsave(){
var fldLink = Xrm.Page.data.entity.attributes.get("fieldname");
if (fldLink) {

fldLink.setValue(fldIntroducedTo.getValue()[0].name + "*" + fldIntroducedTo.getValue()[0].id);

fldLink.setSubmitMode("always");
}



function converttexttoURL(fldName) {try {
var getLinkfromTextField = Xrm.Page.data.entity.attributes.get(fldName);

if (getLinkfromTextField && getLinkfromTextField.getValue()) {

var getdatafromfield = fldLink.getValue();

var btnHTML = "<a href='javascript: void(0);' title='" + getdatafromfield.split('*')[0] + "' onclick=\"openAccount('" + getdatafromfield.split('*')[1] + "')\" style='color:blue;text-decoration:underline !important'>" + getdatafromfield.split('*')[0] + "</a>";

var getFieldControl = document.getElementById(fldName);
if (getFieldControl) {

// Set the new HTML to the field
getFieldControl.innerHTML = btnHTML;}
 
// Show Link field

Xrm.Page.ui.controls.get(fldName).setVisible(true);

}
 
} catch (e) {

alert("Error in convertourl- " + e.description);
}
}


function openAccount(accountId) {

if (Xrm && Xrm.Utility && accountId) {

Xrm.Utility.openEntityForm('account', accountId);
}
}
 
 

Monday, May 2, 2016

Bulk Create in MSCRM 2015 Plugins

Hi All,

Please find the below Script to Bulk Update Records. In My Scinario am having Entity1 and Entity2 entities.
If i update Entity1 Status Entity2 Status also should get update with the same Status.

Code:

 ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
                    {                    
                        Settings = new ExecuteMultipleSettings()
                        {
                            ContinueOnError = true,
                            ReturnResponses = true
                        },
                        Requests = new OrganizationRequestCollection()
                    };

QueryExpression qe = new QueryExpression(Entity2);
qe.ColumnSet = new ColumnSet(true);
qe.Criteria.AddCondition(new ConditionExpression("Entity1id", ConditionOperator.Equal, {GUID OF Entity1} ));
EntityCollection collectAllValues = service.RetrieveMultiple(qe);

 foreach (Entity loopCollectedValues in collectAllValues.Entities)
            {
                Entity getAllrecords = new Entity("Entity2");

                getAllrecords.Id = Entity2.Id;

               getAllrecords.Attributes["new_status"] = new OptionSetValue(((Microsoft.Xrm.Sdk.OptionSetValue)((postImageEntity.Attributes["new_status"]))).Value);

                CreateRequest createRequest = new CreateRequest { Target = getAllrecords  };

                requestWithResults.Requests.Add(createRequest);
            }

ExecuteMultipleResponse responseWithResults =
(ExecuteMultipleResponse)_service.Execute(requestWithResults);
if (responseWithResults.IsFaulted)
                        {
foreach (var responseItem in responseWithResults.Responses)
                            {
                                if (responseItem.Response != null) { }
                                if (responseItem.Fault != null) { }                        
                            }
                        }

Bulk Update Records in CRM 2015

Hi All,

Please find the below Script to Bulk Update Records. In My Scinario am having Entity1 and Entity2 entities.
If i update Entity1 Status Entity2 Status also should get update with the same Status.

Code:

 ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
                    {                      
                        Settings = new ExecuteMultipleSettings()
                        {
                            ContinueOnError = true,
                            ReturnResponses = true
                        },
                        Requests = new OrganizationRequestCollection()
                    };

QueryExpression qe = new QueryExpression(Entity2);
qe.ColumnSet = new ColumnSet(true);
qe.Criteria.AddCondition(new ConditionExpression("Entity1id", ConditionOperator.Equal, {GUID OF Entity1} ));
EntityCollection collectAllValues = service.RetrieveMultiple(qe);

 foreach (Entity loopCollectedValues in collectAllValues.Entities)
            {
                Entity getAllrecords = new Entity("Entity2");

                getAllrecords.Id = Entity2.Id;

               getAllrecords.Attributes["new_status"] = new OptionSetValue(((Microsoft.Xrm.Sdk.OptionSetValue)((postImageEntity.Attributes["new_status"]))).Value);

                UpdateRequest updateRequest = new UpdateRequest { Target = getAllrecords };

                requestWithResults.Requests.Add(updateRequest);
            }

ExecuteMultipleResponse responseWithResults =
(ExecuteMultipleResponse)_service.Execute(requestWithResults);
if (responseWithResults.IsFaulted)
                        {
foreach (var responseItem in responseWithResults.Responses)
                            {
                                if (responseItem.Response != null) { }
                                if (responseItem.Fault != null) { }                        
                            }
                        }

Wednesday, April 27, 2016

Dependencies of Managed Solution MSCRM

Hi,

Please find the below link to find out the dependencies of CRM Managed Solutions

http://{Your Server Name}/{Your Organization name}/tools/dependency/dependencyviewdialog.aspx?objectid={Solution Guid }&objecttype=7100&operationtype=dependenciesforuninstall#

Tuesday, April 12, 2016

Get all User's from Team MSCRM CRM 2013

Hi All,

Please find the below Fetch XML code to fetch all the users from team

function onload()
{
var getUserJS = Xrm.Page.context.getUserId();
getUserJS = getUserJS.replace(/[{}]/g, "");
getUserJS = getUserJS.toLowerCase();
var getusesfromTeam = getUsers(pass Team Id);
if (getusesfromTeam.length > 0) {
for (var getOwningUsers = 0; getOwningUsers < getusesfromTeam.length; getOwningUsers++) {
if (getOwningTeamusers[getOwningUsers].attributes.systemuserid.value == getUserJS) {
return true
         }
     }
   }
}

function getUsers(teamid) {
    var GetUsers = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
  "<entity name='systemuser'>" +
    "<attribute name='fullname' />" +
    "<attribute name='businessunitid' />" +
    "<attribute name='title' />" +
    "<attribute name='mobilephone' />" +
    "<attribute name='systemuserid' />" +
    "<attribute name='positionid' />" +
    "<order attribute='fullname' descending='false' />" +
    "<link-entity name='teammembership' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
      "<link-entity name='team' from='teamid' to='teamid' alias='ac'>" +
        "<filter type='and'>" +
          "<condition attribute='teamid' operator='eq' value='" + teamid + "' />" +
        "</filter>" +
      "</link-entity>" +
    "</link-entity>" +
  "</entity>" +
"</fetch>";

    var OwningUsers = XrmServiceToolkit.Soap.Fetch(GetUsers);
    return OwningUsers;
}

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...