Saturday, May 30, 2015

Filtering on opportunity products lookup ("Existing Product" lookup inside Opportunity Product entity)

function AddNewView2() {

 try {
 $("#productid").attr("disableViewPicker", "0");
 // Parameters
 var customViewId = "FD140AAF-4DF4-11DD-BD17-0019B9312238"; // new id
 var customViewName = "Sales Products";
 var lookupFieldName = "productid";
 var entityName = "product";
 var primaryKeyName = "productid";
 var primaryFieldName = "productid";
 // Create Dynamics View
 AdvancedFilteredLookup2(lookupFieldName, customViewId, entityName, primaryKeyName, primaryFieldName, customViewName);
 $("#productid").attr("disableViewPicker", "1");
 }
 catch (err) {
 }
}

// Advanced Filtered Lookup
function AdvancedFilteredLookup2(lookupSchemaName, viewId, entityName, primaryKeyName, primaryFieldName, viewDisplayName) {
 var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical'>" +
"<entity name='" + entityName + "'>" +
"<attribute name='name' />" +
"<attribute name='producttypecode' />" +
"<attribute name='productnumber' />" +
"<attribute name='" + primaryFieldName + "' />" +
"<order attribute='name' descending='false' />"+
"<filter type='and'>" +                      
    "<condition attribute='ti_salesproduct' operator='eq' value='1' />" +
    "</filter>" +
    "</entity>" +
    "</fetch>";

 var layoutXml = "<grid name='resultset' " +
"object='1024' " +
"jump='name' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='" + primaryKeyName + "'>";

 layoutXml += "<cell name='name' width='300' />";
 layoutXml += "<cell name='productnumber' width='100' />";
 layoutXml += "<cell name='producttypecode' width='150' />";
 layoutXml += "</row></grid>";

 try {
 var lookupControl = Xrm.Page.ui.controls.get("productid");
 lookupControl.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
 }
 catch (err) {
 }
}


Thursday, May 28, 2015

CRM Developer Tools in Visual Studio 2015


It seems CRM Developer Tools are not getting much love from Microsoft lately.

The versions available for CRM 2013 where only for VS2013 and V2012 It’s not been release as part in CRM 2015 SDK yet.

…and VS 2015 is just around the corner…

But there is always a way, ;)…













There are known work around (e.g.: Microsoft Dynamics CRM 2013 Toolkit with Visual Studio 2013) to make this work on VS2013 but I found none so far to deal with VS2015.

After looking around and doing some tests I found a MVW (Minimum Viable Workaround, ;)) to make this work. Two simple steps should do it, as per below:

Add the below to devenv.exe.config

<dependentAssembly>

<assemblyIdentity name="Microsoft.Windows.Design.Host" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

<bindingRedirect oldVersion="4.0.0.0-4.1.0.0" newVersion="4.2.0.0" />

</dependentAssembly>

Install Microsoft.CrmDeveloperToolsVS2015.vsix (my own version with just a view tweaks considering the workaround for VS2013, as per blog linked above)

Tuesday, May 5, 2015

How to update the value of parent entity field while updating child entity in ms crm 2011 using javascript

Parent Entity  to open the child entity in popup windows with selected records

function addPriceEndDate(selecteditemsid)
{
var parameters = {};
parameters["selecteditemsid_0"] = selecteditemsid;
  Xrm.Utility.openEntityForm("cel_priceenddate", null, parameters);    
}

Add the Below parameters in ribbon workbench.



From child entity we updating the parent entity fields in my case I am updating End date. Below is script.

function onPriceEndDateSave()
{
if (getQuerystring('selecteditemsid_0') != null)
{
var accountid = getQuerystring('selecteditemsid_0');
accountid = ReplaceString(accountid ,"%7b","{");
accountid = ReplaceString(accountid ,"%7d","}");
accountid = ReplaceString(accountid ,"%2c",",");
var priceids= new Array();
priceids= accountid.split(",");
for (price in priceids) {
updateRecord(priceids[price]);
}
}
}


function updateRecord(id)
{
debugger;
try
{
var price = {};
price.cel_EndDate = Xrm.Page.getAttribute("cel_priceenddate").getValue();

SDK.REST.updateRecord(
id,
price ,
"cel_price",
function () {
writeMessage("The Price record changes were saved");
},
errorHandler
);

}
catch(e)
{
alert("Failed to Execute");
}
}
function errorHandler(error) {
alert(error.message);
}
function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[[]/,"[").replace(/[]]/,"]");
var regex = new RegExp("[?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}
function ReplaceString(strString, strReplace, strReplaceWith){
if (strString != "" && strReplace != "") {
var re = new RegExp(strReplace, "gi");
var s = strString.replace(re, strReplaceWith);
return s;
}
else{
return strString;
}

}

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