serving the solutions day and night

Pages

Tuesday, May 26, 2015

Unsupported Dynamics CRM database delete operations


Before delete, run SQL Profiler, just delete a single delete operation in CRM and watch all queries involved. 

In this example i am deleting contact entity records, before delete all their related entity records

1.Delete related entities

for example contact related dns_mailings entity (object type code is 12345)
declare  @c table(c varchar(max))

insert into @c select  dns_mailingsid from dns_mailings where dns_name = 'Test 2015'
--select * from @c

delete from dns_mailingsExtensionBase where (dns_mailingsid in (select c from @c));
delete from dns_mailingsBase
OUTPUT DELETED.dns_mailingsid , 12345
into SubscriptionTrackingDeletedObject (ObjectId, ObjectTypeCode)
 where (dns_mailingsid in (select c from @c))

delete from [EmailSearchBase]
OUTPUT DELETED.[EmailSearchId], 4299
into SubscriptionTrackingDeletedObject (ObjectId, ObjectTypeCode)
 where ([ParentObjectId] in (select c from @c))

 update [ActivityPartyBase] set [IsPartyDeleted]=1 where ([PartyId] in (select c from @c)) and [PartyObjectTypeCode] =12345


Thursday, May 21, 2015

Dynamic CRM Hide/Show ribbon button by OnChange lookup field

1)create a javascript (HideShow.js), 2 functions

var HideShowButton = {
//refresh the ribbon when lookup field on change.
OnChangeLookup: function () {
        Xrm.Page.ui.refreshRibbon();
  },

//Show and Hide when form load
EnableCustomRule: function () {
if (Xrm.Page.data.entity.attributes.get("contactid") != null) {
   var contactId = Xrm.Page.data.entity.attributes.get("contactid").getValue()[0].id;
   var req = new XMLHttpRequest();
   var url = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet(guid'" + contactId + "')?$select=photoonfile";
   req.open("GET", encodeURI(url), false);
   req.setRequestHeader("Accept", "application/json");
   req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
   req.send();
   var data = JSON.parse(req.responseText).d;
   if (data.photoonfile == null || data.photoonfile == false) {
return true;
   }
   return false;
}
},
};