Tuesday, May 17, 2016

Load External javascript MSCRM 2011

HI All,

Please find the below code to call external Javasctipt webresources

(Eg)

I have Update function in "new_JQuery"

but now am working in "new_new_JQuery1" function so if i use below code i can directly access Update function from "new_JQuery"  to "new_new_JQuery1".


var url="../WebResources/new_JQuery";
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET",url,false);
xmlHttp.send();
eval(xmlHttp.responseText);

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) { }                        
                            }
                        }

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...