Tuesday, April 10, 2018

Unable to Login to Dynamics CRMOrganizationWebProxyClient is nullOrganizationWebProxyClient is nullOrganizationServiceProxy is nullOrganizationServiceProxy is null

Hi All,

If any one facing the issue in Console application while connecting to MSCRM(onpremises) with IFD as Unable to Login to Dynamics CRMOrganizationWebProxyClient is null. Use the below connection string to made it work

Old Code:

CrmServiceClient crmConn = new CrmServiceClient("AuthType=IFD; Url=https://ServerName/Orgname; Domain=domainName; Username=username; Password=password");

Change the Old Code to New Code as Below

CrmServiceClient crmConn = new CrmServiceClient("AuthType=IFD; Url=https://ServerName/Orgname; Domain=domainName; Username=username@domainName; Password=password");



Monday, February 19, 2018

Get the Created Records when Lead Gets Qualified - Microsoft dynamics CRM

Hi All,

Once Lead Gets Qualify, as per oob behavior it will automatically create opportunity, contact and accounts.

As per my logic whenever an opportunity gets created need to set created lead id to custom opportunity field.

Plugin Step Creation:


Register Plugin as Asynchronously


            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            OrganizationServiceContext orgContext = new OrganizationServiceContext(service);

EntityReference getLeadid = (EntityReference)context.InputParameters["LeadId"];
Entity lead = service.Retrieve("lead", leadid.Id, new ColumnSet(true));

foreach (EntityReference CreatedEntityFromLead in ((IEnumerable)context.OutputParameters["CreatedEntities"]))
                {
                    if (CreatedEntityFromLead.LogicalName == "opportunity")
                    {
                        Entity entOpportunity = service.Retrieve("opportunity", CreatedEntityFromLead.Id, new ColumnSet(true));
                         entOpportunity["new_customLookupid"] = erLookUpField;
                        service.Update(entOpportunity);
                    }

                }




Tuesday, February 6, 2018

Selection Count Rule - Display Custom ribbon button only if atleast single record is selected in a Home Page

Hi All,

Display Custom ribbon button only if at-least single record is selected in a Home Page

Add the Below Enable Rule to the Custom Created Command and publish it.

Enable Rule:





Monday, February 5, 2018

ILMerge Visual Studio

Hi All,

As we already Known that ILMerge we can use to Merge dll’s, in some situation we can’t find the proper expectation Solution while Surfing. So am writing this blog for my safe and Global if needed.

In below Scinario I need to merger workflow.dll + Newtonsoft.json.dll + strongfile.snk = Workflow_Merged.dll

"$(TargetDir)\ILMerge.exe" "$(TargetDir)Workflow.dll" "$(TargetDir)\Newtonsoft.Json.dll" "/keyfile:$(SolutionDir)Workflow\Workflow.snk" /out:"$(TargetDir)\Workflow_Merged.dll"

Note:
Download ILmerge from : ILMerge
(TargerDir) --> Root Directory
(SolutionDir) --> Solution Directory

Wednesday, January 10, 2018

Batch Job Execution MSCRM JavaScript Update

Hi All,

Code below mentioned for BULK Update of Batch Job in MSCRM 2016


function BulkUpdate(multipleEntityIds, destinationEntity) {
            var data = [];
            data.push('--batch_123456');
            data.push('Content-Type: multipart/mixed;boundary=changeset_BBB456');
            data.push('');
            for (var i = 0; i < multipleEntityIds.length; i++) {
                data.push('--changeset_BBB456');
                data.push('Content-Type:application/http');
                data.push('Content-Transfer-Encoding:binary');
                data.push('Content-ID:' + i);
                data.push('');
                data.push('PATCH ' + parent.Xrm.Page.context.getClientUrl() + '/api/data/v8.1/' + destinationEntity + '(' + multipleEntityIds[i].replace("{", "").replace("}", "") + ')' + ' HTTP/1.1');
                data.push('Content-Type:application/json;type=entry');
                data.push('');
                data.push('{ "pa_description":"' + descriptionValues + '" }');
            }

            //end of changeset
            data.push('--changeset_BBB456--');
            //end of batch
            data.push('--batch_123456--');
            var payload = data.join('\r\n');

            $.ajax(
            {
                method: 'PATCH',
                url: Xrm.Page.context.getClientUrl() + '/api/data/v8.1/$batch',
                headers: {
                    'Content-Type': 'multipart/mixed;boundary=batch_123456',
                    'Accept': 'application/json',
                    'Odata-MaxVersion': '4.0',
                    'Odata-Version': '4.0'
                },

                data: payload,
                async: false,
                success: function (data, textStatus, xhr) {
                    var splitstring = currentIds.split(",");
                    for (var i = 0; i < splitstring.length; i++) {
                        alert("Updated Successfully");
                    }
                },
                error: function (xhr, data, textStatus, errorThrown) {
                    alert(data, textStatus + " " + errorThrown);
                }
            });
        }

Tuesday, January 9, 2018

HTML Page + Xrm.Internal.openDialog with Call back Function MSCRM 2016

Hi All,

We got a requirement that on click of Deactivate Button in contact, we need to call custom HTML Page to get Data and we need to update the same in Contact Entity and need to deactivate the Record.
RIBBON BUTTON CHANGES:
Open Ribbon Work Bench à Select your Solution à Click Deactivate Button à Right Click and Customize Commandà Change the Library to new one which you created à change the Function to OpenHTMLPage

Add a new CRMParameter and make a Priority as First to pass OBJECT TYPE CODE.



JAVASCRIPT FUNCTION:

function OpenHTMLPage(predefinedparameters) {
    debugger;
    var currentRecId = Xrm.Page.data.entity.getId();
    var someText = "info";
    var addParams = "recordid=" + currentRecId + "&entityname=" + Xrm.Page.data.entity.getEntityName() + "&entitytypecode=" + predefinedparameters;
    //Build the URI
    var src = "/WebResources/pa_HTMLPage.html?Data=" + encodeURIComponent(addParams);
    //Build dialog options
    var DialogOptions = new Xrm.DialogOptions();
    DialogOptions.width = 400;
    DialogOptions.height = 260;

    Xrm.Internal.openDialog(src, DialogOptions, null, null, CallbackFunction);
}
//Execute some action on closing of dialog
function CallbackFunction(returnValue) {
    Xrm.Page.data.refresh();
}


HTML PAGE:

<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="../WebResources/pa_jquery.1.9.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        Mscrm.Utilities.setReturnValue("close");
        var entityEnum = {
            2: "contacts",
        };
        function ParseQueryString(query) {
            var result = {};
            if (typeof query == "undefined" || query == null) {
                return result;
            }
            var queryparts = query.split("&");
            for (var i = 0; i < queryparts.length; i++) {
                var params = queryparts[i].split("=");
                result[params[0]] = params.length > 1 ? params[1] : null;
            }
            return result;
        }

        function updateRequest(destinationUpdateRequest, destinationUpdateEntity) {
            var req = new XMLHttpRequest();
            req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/" + destinationUpdateEntity + "", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
            req.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 204) {
                        var GetEntityName = entityEnum[entityTypeCode];
                        var updateEntityRequest = GetEntityName + "(" + currentRecId.replace("{", "").replace("}", "") + ")";
                        deactivateRecord(updateEntityRequest);
                    } else {
                        document.getElementById('alertLabel').innerHTML = 'Error: Please contact System Administrator';
                    }
                }
            };
            req.send(JSON.stringify(destinationUpdateRequest));
        }
        var passedparams = "";
        var currentRecId = "";
        var entityName = "";
        var entityTypeCode = "";
        function processSubmitButton() {
            debugger;
            document.getElementById('alertLabel').innerHTML = 'Please Wait...';
            passedparams = ParseQueryString(GetGlobalContext().getQueryStringParameters()["Data"]);
            currentRecId = passedparams.recordid;
            entityName = passedparams.entityname;
            entityTypeCode = passedparams.entitytypecode;
            var entity = {};
            entity.contact_description = document.getElementById("descriptionValues").value;
            var GetEntityName = entityEnum[entityTypeCode];
            var updateEntityRequest = GetEntityName + "(" + currentRecId.replace("{", "").replace("}", "") + ")";
            updateRequest(entity, updateEntityRequest);
        }

        function deactivateRecord(destinationUpdateEntity) {
            var entity = {};
            entity.statuscode = 2;
            entity.statecode = 1;

            var req = new XMLHttpRequest();
            req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/" + destinationUpdateEntity + "", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 204) {
                        Mscrm.Utilities.setReturnValue(true);
                        closeWindow();
                    }
                    else {
                        Xrm.Utility.alertDialog(this.statusText);
                    }
                }
            };
            req.send(JSON.stringify(entity));

        }
    </script>
    <style>
        h5 {
            font-family: Segoe UI,Tahoma,Arial;
            font-weight: bold;
            font-variant: normal;
            color: #000080;
            text-decoration: underline;
        }

        h6 {
            font-family: Segoe UI,Tahoma,Arial;
            font-weight: bold;
            font-variant: normal;
        }

        p {
            font-family: Segoe UI,Tahoma,Arial;
            font-size: 13px;
        }
    </style>

    <meta>
    <meta>
    <meta>
    <meta>
</head>

<body style="word-wrap: break-word;">
    <h5> Please Enter your Comments </h5>
    <textarea rows="4" cols="75" name="comment" id="descriptionValues">    </textarea>&nbsp;<div style="font-family: undefined;"><br></div><div style="font-family: undefined;">
        <button type="button" id="OnSubmitButtonClick" onclick="processSubmitButton()">Submit</button>
        <h6><label id="alertLabel"></label></h6>
    </div>

</body>
</html>

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