Tuesday, December 29, 2015

Modify the Columns Shown in The Inline Lookup-CRM 2013 & 2015


How to modify the columns shown in the inline lookup in CRM 2013 Refreshed Entity User Interface and what can be done and what cannot be done.

image

In the example (lookup to Contact), it shows only Name, Company Name, and Email Address.

You found that Email Address is not important, you want to show Name, City, and Company Name.

Explanation:

1. Go to Form Editor

2. Go to the field and check the lookup that is used, in this case is Contact view (lookup view) and get the Default View of the Lookup field

image

*You can also use custom view as default view.

image

3. Go to the Contact Lookup View and then you add can re-order the position

Previously:

image

Change to:

image

*You cannot modify the Full Name position nor remove it.

4. Test the Result:

image

*The supported total column shown in the inline lookup is 3 only (including Name as the primary field that is not replaceable)

It shows Name, City, and Company Name as per your expectation.

5. You can also use a Composite field, for example, Address

image

Result:

image

And you can get the tooltip.

image

6. But, you cannot use to show field from related entity.

Example:

image

Order: Name, City, Industry of the Account, Company Name

Result:

image

You should ‘Look Up More Records’

image

Activate – Deactivate Record using JavaScript in CRM


Activate – Deactivate Record using JavaScript in CRM


//Params:entityname,entityGuid,stateCode,StatusCode
// Call the funtion
changeRecordStatus("contact", Xrm.Page.data.entity.getId(), 1, 2);


function changeRecordStatus(EntityLogicalName, RECORD_ID, stateCode, statusCode) {

    // create the SetState request

    var request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";

    request += "<s:Body>";

    request += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";

    request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";

    request += "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";

    request += "<a:KeyValuePairOfstringanyType>";

    request += "<c:key>EntityMoniker</c:key>";

    request += "<c:value i:type=\"a:EntityReference\">";

    request += "<a:Id>" + RECORD_ID + "</a:Id>";

    request += "<a:LogicalName>" + EntityLogicalName + "</a:LogicalName>";

    request += "<a:Name i:nil=\"true\" />";

    request += "</c:value>";

    request += "</a:KeyValuePairOfstringanyType>";

    request += "<a:KeyValuePairOfstringanyType>";

    request += "<c:key>State</c:key>";

    request += "<c:value i:type=\"a:OptionSetValue\">";

    request += "<a:Value>" + stateCode + "</a:Value>";

    request += "</c:value>";

    request += "</a:KeyValuePairOfstringanyType>";

    request += "<a:KeyValuePairOfstringanyType>";

    request += "<c:key>Status</c:key>";

    request += "<c:value i:type=\"a:OptionSetValue\">";

    request += "<a:Value>" + statusCode + "</a:Value>";

    request += "</c:value>";

    request += "</a:KeyValuePairOfstringanyType>";

    request += "</a:Parameters>";

    request += "<a:RequestId i:nil=\"true\" />";

    request += "<a:RequestName>SetState</a:RequestName>";

    request += "</request>";

    request += "</Execute>";

    request += "</s:Body>";

    request += "</s:Envelope>";

    //send set state request

    $.ajax({

        type: "POST",

        contentType: "text/xml; charset=utf-8",

        datatype: "xml",

        url: Xrm.Page.context.getServerUrl() + "/XRMServices/2011/Organization.svc/web",

        data: request,

        beforeSend: function (XMLHttpRequest) {

            XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");

            XMLHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");

        },

        success: function (data, textStatus, XmlHttpRequest) {

            Xrm.Page.data.refresh(); // refresr current crm form

        },

        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert(errorThrown);

        }

    });

}

Friday, December 18, 2015

Using New Scripting Methods in CRM 2016

With the release of Dynamics CRM 2016, new client side methods introduced that we can use to make user experience more interactive while enter data in CRM forms. Following are the methods:
getValue
Keypress
Autocomplete

getValue Method – This method is used to get the latest value of the field. Earlier this method was only available in attribute collection, which provides value of the field only after Onchange event fired. Whereas when it is used with control collection, we can capture value as soon as users starts entering value in field, so it means if we have any requirement to validate data entry then we can use this method to make it more interactive. We can use this method like below:


Xrm.Page.getControl(field name).getValue();
Let’s take one example that we want to restrict user to enter only number between 0-9 under phone field in account entity, so we can simply use below code to do that:





function OnTelephone1KeyPress() {
    var phoneValue = Xrm.Page.getControl("telephone1").getValue().toString().replace(/[^0-9]/g, "");
    Xrm.Page.getAttribute("telephone1").setValue(phoneValue);
}
Above code will get character from telephone1 field as soon as user enters it and will replace character with null if it is not under 0 to 9 range. But we need to use above code with keypress events, so let’s understand use of keypress event first to complete our code.
Keypress Method – Below three keypress methods are added to work with controls:
addOnKeyPress – This method is used to associate method to KeyPress event of text or number, so it will fire when user will press any key. We can use this method like below:

1
Xrm.Page.getControl(field name).addOnKeyPress(name of function);
For example if we want to call above method on keypress event of telephone1 field then we can use it like below:
1
Xrm.Page.getControl("telephone1").addOnKeyPress(OnTelephone1KeyPress);
Now let’s deploy this code to CRM, we can create a java script web resource and use below code under text editor:









//validate character
function OnTelephone1KeyPress() {
    var phoneValue = Xrm.Page.getControl("telephone1").getValue().toString().replace(/[^0-9]/g, "");
    Xrm.Page.getAttribute("telephone1").setValue(phoneValue);
}
//add keypress event handler
function AccountOnLoad() {
    Xrm.Page.getControl("telephone1").addOnKeyPress(OnTelephone1KeyPress);
}
clientevent1
After that we need to attach this web resource to account entity form and need to call AccountOnLoad method OnLoad of account form like below and need save and publish our changes: clientevent2
Now when we will create a new account record or modify existing account record, we will see our code won’t allow us to enter non numeric character under phone field.

removeOnKeyPress – We can use this method to remove KeyPress event handler from the text or number field, that is added using addOnKeyPress method. We can use it like below:
1
Xrm.Page.getControl(arg).removeOnKeyPress(function name)
fireOnKeyPress – We can use this method to call KeyPress event handler for text or number field, we can use it like below:
1
Xrm.Page.getControl(field name).fireOnKeyPress()
Note: All the above methods are only supported for Web and Outlook client.

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...