×

Dynamics 365 CRM v9 – Forma Sub-Grid Eklerken Oluşan Hatanın Çözümü

Giriş

Microsoft Dynamics 365 CRM v9 On-Premise ortamlarında form özelleştirmeleri sırasında bazı durumlarda forma yeni bir Sub-Grid eklenmek istendiğinde beklenmeyen bir hata ile karşılaşılabilir.

Özellikle mevcut bir entity formuna Sub-Grid ekleme veya ilgili relationship üzerinden kayıtların görüntülenmesini sağlayacak bir bileşen oluşturma sırasında işlem tamamlanamayabilir ve CRM generic bir hata mesajı gösterebilir.

Sorunun kaynağı her zaman formun kendisi veya eklenmeye çalışılan Sub-Grid değildir. Bazı Dynamics 365 v9 ortamlarında problem, CRM metadata yapısında bulunan belirli Entity Relationship ve Dependency kayıtlarının hatalı ilişkilendirilmesinden kaynaklanabilir.

Bu makalede ilgili metadata tutarsızlığının giderilmesi ve Sub-Grid ekleme işleminin tekrar çalışır hale getirilmesi için uygulanabilecek çözüm ele alınmaktadır.

Çözüm

Problemin giderilmesi için Dynamics 365 CRM Organization veritabanındaki hatalı relationship ve dependency metadata kayıtlarının düzeltilmesi gerekmektedir.

Aşağıdaki SQL scripti ilgili metadata kayıtlarını kontrol ederek BulkOperation ve CampaignActivity tarafındaki Lead, Account ve Contact ilişkilerinde gerekli düzeltmeleri gerçekleştirir.

Script aşağıdaki altı ilişkiyi kontrol etmektedir:

  • BulkOperation_Leads
  • BulkOperation_Accounts
  • BulkOperation_Contacts
  • CampaignActivity_Leads
  • CampaignActivity_Accounts
  • CampaignActivity_Contacts

Script, hatalı relationship kayıtlarını doğru relationship kayıtlarıyla eşleştirmenin yanı sıra ilgili DependencyBase kayıtlarını da günceller. Yapılan düzeltme sayısını takip eder ve altı düzeltmenin tamamlanması durumunda EXECUTION SUCCEEDED mesajını üretir.

Tüm işlemler transaction içerisinde gerçekleştirilmektedir. SQL seviyesinde bir hata meydana gelmesi durumunda ROLLBACK TRAN çalıştırılarak transaction geri alınır.

Önemli: Script Dynamics 365 Organization veritabanındaki metadata tablolarına doğrudan müdahale etmektedir. Production ortamında uygulanmadan önce ilgili Organization veritabanının backup’ı alınmalı ve mümkünse işlem öncelikle test ortamında doğrulanmalıdır.

SQL Script

BEGIN TRY

    BEGIN TRAN t1

declare @attributeGuid uniqueidentifier =
'e305e856-189e-487c-84bc-8ff5e858277f'

declare @CorrectRelationshipIdLead uniqueidentifier;

declare @CorrectRelationshipIdAccount uniqueidentifier;

declare @CorrectRelationshipIdContact uniqueidentifier;

declare @RelationshipIdBulkOperationLogs uniqueidentifier;

declare @RelationshipIdCampaignActivityLogs uniqueidentifier;

declare @CorrectRelationshipId uniqueidentifier

declare @EntityRelationshipId uniqueidentifier;

declare @WrongRelationshipId uniqueidentifier;

declare @WrongEntityRelationshipRelationshipId uniqueidentifier;

declare @WrongRowsCount int; 

declare @FixesApplied int;

select @RelationshipIdBulkOperationLogs = RelationshipId from
Relationship where Name = 'BulkOperation_logs'

select @RelationshipIdCampaignActivityLogs = RelationshipId from
Relationship where Name =
'CampaignActivity_logs'                

set @FixesApplied = 0

/***** 1. BulkOperation_Leads *****/

DECLARE @WrongRelationshipIdLead UniqueIdentifier

Set @WrongRelationshipIdLead = (SELECT DISTINCT RelationshipId FROM
Relationship WHERE Name = 'CreatedLead_BulkOperationLogs')

DECLARE @WrongRelationshipDependencyNodeIdLead UniqueIdentifier

Set @WrongRelationshipDependencyNodeIdLead = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@WrongRelationshipIdLead)

select @CorrectRelationshipIdLead = RelationshipId from Relationship
where Name = 'SourceLead_BulkOperationLogs' and (ReferencedAttributeId =
@attributeGuid or ReferencingAttributeId = @attributeGuid)
        
set @CorrectRelationshipId = @CorrectRelationshipIdLead;

DECLARE @CorrectRelationshipDependencyNodeIdLead UniqueIdentifier

Set @CorrectRelationshipDependencyNodeIdLead = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@CorrectRelationshipId)

select @EntityRelationshipId = EntityRelationshipId from
EntityRelationship where SchemaName = 'BulkOperation_Leads'

DECLARE @EntityRelationshipsRelationshipIdLead UniqueIdentifier

Set @EntityRelationshipsRelationshipIdLead = 

(SELECT DISTINCT EntityRelationshipRelationshipsId FROM
EntityRelationshipRelationships 

WHERE EntityRelationshipId = @EntityRelationshipId

AND RelationshipId = @WrongRelationshipIdLead )

select @WrongRowsCount = count(*) from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdLead

if @WrongRowsCount >= 1 

begin

select @WrongRelationshipId = RelationshipId,
@WrongEntityRelationshipRelationshipId = EntityRelationshipRelationshipsRowId 

from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdLead;

PRINT 'Fixing BulkOperation_Leads - To revert: update
EntityRelationshipRelationships set RelationshipId = ''' +
CONVERT(VARCHAR(255), @WrongRelationshipId) + ''' where
EntityRelationshipRelationshipsRowId = ''' + CONVERT(VARCHAR(255),
@WrongEntityRelationshipRelationshipId) + '''';

update EntityRelationshipRelationships 

set RelationshipId = @CorrectRelationshipId 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs);

SELECT @@ROWCOUNT

UPDATE DependencyBase

SET DependentComponentNodeId = @CorrectRelationshipDependencyNodeIdLead

WHERE RequiredComponentNodeId = (SELECT DependencyNodeId FROM
DependencyNodeBase WHERE ObjectId = @EntityRelationshipsRelationshipIdLead)

AND DependentComponentNodeId = @WrongRelationshipDependencyNodeIdLead

SELECT @@ROWCOUNT

set @FixesApplied = @FixesApplied + 1

end

else

PRINT 'FAILED to fix BulkOperation_Leads';


/***** 2. BulkOperation_Accounts *****/

DECLARE @WrongRelationshipIdAccount UniqueIdentifier

Set @WrongRelationshipIdAccount = (SELECT DISTINCT RelationshipId FROM
Relationship WHERE Name = 'CreatedAccount_BulkOperationLogs2')

DECLARE @WrongRelationshipDependencyNodeIdAccount UniqueIdentifier

Set @WrongRelationshipDependencyNodeIdAccount = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@WrongRelationshipIdAccount)

select @CorrectRelationshipIdAccount = RelationshipId from Relationship
where Name = 'SourceAccount_BulkOperationLogs' and (ReferencedAttributeId =
@attributeGuid or ReferencingAttributeId = @attributeGuid)
        
set @CorrectRelationshipId = @CorrectRelationshipIdAccount;

DECLARE @CorrectRelationshipDependencyNodeIdAccount UniqueIdentifier

Set @CorrectRelationshipDependencyNodeIdAccount = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@CorrectRelationshipId)

select @EntityRelationshipId = EntityRelationshipId from
EntityRelationship where SchemaName = 'BulkOperation_Accounts'

DECLARE @EntityRelationshipsRelationshipIdAccount UniqueIdentifier

Set @EntityRelationshipsRelationshipIdAccount = 

(SELECT DISTINCT EntityRelationshipRelationshipsId FROM
EntityRelationshipRelationships 

WHERE EntityRelationshipId = @EntityRelationshipId

AND RelationshipId = @WrongRelationshipIdAccount )

select @WrongRowsCount = count(*) from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdAccount

if @WrongRowsCount >= 1 

begin

select @WrongRelationshipId = RelationshipId,
@WrongEntityRelationshipRelationshipId = EntityRelationshipRelationshipsRowId 

from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdAccount;

PRINT 'Fixing BulkOperation_Accounts - To revert: update
EntityRelationshipRelationships set RelationshipId = ''' +
CONVERT(VARCHAR(255), @WrongRelationshipId) + ''' where
EntityRelationshipRelationshipsRowId = ''' + CONVERT(VARCHAR(255),
@WrongEntityRelationshipRelationshipId) + '''';

update EntityRelationshipRelationships 

set RelationshipId = @CorrectRelationshipId 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs);

SELECT @@ROWCOUNT

UPDATE DependencyBase

SET DependentComponentNodeId =
@CorrectRelationshipDependencyNodeIdAccount

WHERE RequiredComponentNodeId = (SELECT DependencyNodeId FROM
DependencyNodeBase WHERE ObjectId = @EntityRelationshipsRelationshipIdAccount)

AND DependentComponentNodeId =
@WrongRelationshipDependencyNodeIdAccount

SELECT @@ROWCOUNT

set @FixesApplied = @FixesApplied + 1

end

else

PRINT 'FAILED to fix BulkOperation_Accounts';


/***** 3. BulkOperation_Contacts *****/

DECLARE @WrongRelationshipIdContact UniqueIdentifier

Set @WrongRelationshipIdContact = (SELECT DISTINCT RelationshipId FROM
Relationship WHERE Name = 'CreatedContact_BulkOperationLogs')

DECLARE @WrongRelationshipDependencyNodeIdContact UniqueIdentifier

Set @WrongRelationshipDependencyNodeIdContact = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@WrongRelationshipIdContact)

select @CorrectRelationshipIdContact = RelationshipId from Relationship
where Name = 'SourceContact_BulkOperationLogs' and (ReferencedAttributeId =
@attributeGuid or ReferencingAttributeId = @attributeGuid)
        
set @CorrectRelationshipId = @CorrectRelationshipIdContact;

DECLARE @CorrectRelationshipDependencyNodeIdContact UniqueIdentifier

Set @CorrectRelationshipDependencyNodeIdContact = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@CorrectRelationshipId)

select @EntityRelationshipId = EntityRelationshipId from
EntityRelationship where SchemaName = 'BulkOperation_Contacts'

DECLARE @EntityRelationshipsRelationshipIdContact UniqueIdentifier

Set @EntityRelationshipsRelationshipIdContact = 

(SELECT DISTINCT EntityRelationshipRelationshipsId FROM
EntityRelationshipRelationships 

WHERE EntityRelationshipId = @EntityRelationshipId

AND RelationshipId = @WrongRelationshipIdContact )

select @WrongRowsCount = count(*) from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdContact

if @WrongRowsCount >= 1 

begin

select @WrongRelationshipId = RelationshipId,
@WrongEntityRelationshipRelationshipId = EntityRelationshipRelationshipsRowId 

from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdContact;

PRINT 'Fixing BulkOperation_Contacts - To revert: update
EntityRelationshipRelationships set RelationshipId = ''' +
CONVERT(VARCHAR(255), @WrongRelationshipId) + ''' where
EntityRelationshipRelationshipsRowId = ''' + CONVERT(VARCHAR(255),
@WrongEntityRelationshipRelationshipId) + '''';

update EntityRelationshipRelationships 

set RelationshipId = @CorrectRelationshipId 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs);

SELECT @@ROWCOUNT

UPDATE DependencyBase

SET DependentComponentNodeId =
@CorrectRelationshipDependencyNodeIdContact

WHERE RequiredComponentNodeId = (SELECT DependencyNodeId FROM
DependencyNodeBase WHERE ObjectId = @EntityRelationshipsRelationshipIdContact)

AND DependentComponentNodeId =
@WrongRelationshipDependencyNodeIdContact

SELECT @@ROWCOUNT

set @FixesApplied = @FixesApplied + 1

end

else

PRINT 'FAILED to fix BulkOperation_Contacts';


/***** 4. CampaignActivity_Leads *****/

DECLARE @WrongRelationshipIdLeadForCA UniqueIdentifier

Set @WrongRelationshipIdLeadForCA = (SELECT DISTINCT RelationshipId
FROM Relationship WHERE Name = 'CreatedLead_BulkOperationLogs')

DECLARE @WrongRelationshipDependencyNodeIdLeadForCA UniqueIdentifier

Set @WrongRelationshipDependencyNodeIdLeadForCA = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@WrongRelationshipIdLeadForCA)

DECLARE @CorrectRelationshipIdLeadForCA uniqueidentifier;

select @CorrectRelationshipIdLeadForCA = RelationshipId from
Relationship where Name = 'SourceLead_BulkOperationLogs' and
(ReferencedAttributeId = @attributeGuid or ReferencingAttributeId =
@attributeGuid)         

set @CorrectRelationshipId = @CorrectRelationshipIdLeadForCA;

DECLARE @CorrectRelationshipDependencyNodeIdLeadForCA UniqueIdentifier

Set @CorrectRelationshipDependencyNodeIdLeadForCA = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@CorrectRelationshipId)

select @EntityRelationshipId = EntityRelationshipId from
EntityRelationship where SchemaName = 'CampaignActivity_Leads'

DECLARE @EntityRelationshipsRelationshipIdLeadForCA UniqueIdentifier

Set @EntityRelationshipsRelationshipIdLeadForCA = 

(SELECT DISTINCT EntityRelationshipRelationshipsId FROM
EntityRelationshipRelationships 

WHERE EntityRelationshipId = @EntityRelationshipId

AND RelationshipId = @WrongRelationshipIdLeadForCA )

select @WrongRowsCount = count(*) from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdLeadForCA

if @WrongRowsCount >= 1 

begin

select @WrongRelationshipId = RelationshipId,
@WrongEntityRelationshipRelationshipId = EntityRelationshipRelationshipsRowId 

from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdLeadForCA;

PRINT 'Fixing CampaignActivity_Leads - To revert: update
EntityRelationshipRelationships set RelationshipId = ''' +
CONVERT(VARCHAR(255), @WrongRelationshipId) + ''' where
EntityRelationshipRelationshipsRowId = ''' + CONVERT(VARCHAR(255),
@WrongEntityRelationshipRelationshipId) + '''';

update EntityRelationshipRelationships 

set RelationshipId = @CorrectRelationshipId 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs);

SELECT @@ROWCOUNT

UPDATE DependencyBase

SET DependentComponentNodeId =
@CorrectRelationshipDependencyNodeIdLeadForCA

WHERE RequiredComponentNodeId = (SELECT DependencyNodeId FROM
DependencyNodeBase WHERE ObjectId =
@EntityRelationshipsRelationshipIdLeadForCA)

AND DependentComponentNodeId =
@WrongRelationshipDependencyNodeIdLeadForCA

SELECT @@ROWCOUNT

set @FixesApplied = @FixesApplied + 1

end

else

PRINT 'FAILED to fix CampaignActivity_Leads';


/***** 5. CampaignActivity_Accounts *****/

DECLARE @WrongRelationshipIdAccountForCA UniqueIdentifier

Set @WrongRelationshipIdAccountForCA = (SELECT DISTINCT RelationshipId
FROM Relationship WHERE Name = 'CreatedAccount_BulkOperationLogs2')

DECLARE @WrongRelationshipDependencyNodeIdAccountForCA UniqueIdentifier

Set @WrongRelationshipDependencyNodeIdAccountForCA = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@WrongRelationshipIdAccountForCA)

DECLARE @CorrectRelationshipIdAccountForCA uniqueidentifier;

select @CorrectRelationshipIdAccountForCA = RelationshipId from
Relationship where Name = 'SourceAccount_BulkOperationLogs' and
(ReferencedAttributeId = @attributeGuid or ReferencingAttributeId =
@attributeGuid)         

set @CorrectRelationshipId = @CorrectRelationshipIdAccountForCA;

DECLARE @CorrectRelationshipDependencyNodeIdAccountForCA
UniqueIdentifier

Set @CorrectRelationshipDependencyNodeIdAccountForCA = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@CorrectRelationshipId)

select @EntityRelationshipId = EntityRelationshipId from
EntityRelationship where SchemaName = 'CampaignActivity_Accounts'

DECLARE @EntityRelationshipsRelationshipIdAccountForCA UniqueIdentifier

Set @EntityRelationshipsRelationshipIdAccountForCA = 

(SELECT DISTINCT EntityRelationshipRelationshipsId FROM
EntityRelationshipRelationships 

WHERE EntityRelationshipId = @EntityRelationshipId

AND RelationshipId = @WrongRelationshipIdAccountForCA )

select @WrongRowsCount = count(*) from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdAccountForCA

if @WrongRowsCount >= 1 

begin

select @WrongRelationshipId = RelationshipId,
@WrongEntityRelationshipRelationshipId = EntityRelationshipRelationshipsRowId 

from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdAccountForCA;

PRINT 'Fixing CampaignActivity_Accounts - To revert: update
EntityRelationshipRelationships set RelationshipId = ''' +
CONVERT(VARCHAR(255), @WrongRelationshipId) + ''' where
EntityRelationshipRelationshipsRowId = ''' + CONVERT(VARCHAR(255), @WrongEntityRelationshipRelationshipId)
+ '''';

update EntityRelationshipRelationships 

set RelationshipId = @CorrectRelationshipId 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs);

SELECT @@ROWCOUNT

UPDATE DependencyBase

SET DependentComponentNodeId =
@CorrectRelationshipDependencyNodeIdAccountForCA

WHERE RequiredComponentNodeId = (SELECT DependencyNodeId FROM
DependencyNodeBase WHERE ObjectId =
@EntityRelationshipsRelationshipIdAccountForCA)

AND DependentComponentNodeId =
@WrongRelationshipDependencyNodeIdAccountForCA

SELECT @@ROWCOUNT

set @FixesApplied = @FixesApplied + 1

end

else

PRINT 'FAILED to fix CampaignActivity_Accounts';


/***** 6. CampaignActivity_Contacts *****/

DECLARE @WrongRelationshipIdContactForCA UniqueIdentifier

Set @WrongRelationshipIdContactForCA = (SELECT DISTINCT RelationshipId
FROM Relationship WHERE Name = 'CreatedContact_BulkOperationLogs')

DECLARE @WrongRelationshipDependencyNodeIdContactForCA UniqueIdentifier

Set @WrongRelationshipDependencyNodeIdContactForCA = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@WrongRelationshipIdContactForCA)

DECLARE @CorrectRelationshipIdContactForCA uniqueidentifier;

select @CorrectRelationshipIdContactForCA = RelationshipId from
Relationship where Name = 'SourceContact_BulkOperationLogs' and
(ReferencedAttributeId = @attributeGuid or ReferencingAttributeId =
@attributeGuid)         

set @CorrectRelationshipId = @CorrectRelationshipIdContactForCA;

DECLARE @CorrectRelationshipDependencyNodeIdContactForCA
UniqueIdentifier

Set @CorrectRelationshipDependencyNodeIdContactForCA = 

(SELECT DependencyNodeId FROM DependencyNodeBase WHERE ObjectId =
@CorrectRelationshipId)

select @EntityRelationshipId = EntityRelationshipId from
EntityRelationship where SchemaName = 'CampaignActivity_Contacts'

DECLARE @EntityRelationshipsRelationshipIdContactForCA UniqueIdentifier

Set @EntityRelationshipsRelationshipIdContactForCA = 

(SELECT DISTINCT EntityRelationshipRelationshipsId FROM
EntityRelationshipRelationships 

WHERE EntityRelationshipId = @EntityRelationshipId

AND RelationshipId = @WrongRelationshipIdContactForCA )

select @WrongRowsCount = count(*) from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdContactForCA

if @WrongRowsCount >= 1 

begin

select @WrongRelationshipId = RelationshipId,
@WrongEntityRelationshipRelationshipId = EntityRelationshipRelationshipsRowId 

from EntityRelationshipRelationships 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs) and
RelationshipId = @WrongRelationshipIdContactForCA;

PRINT 'Fixing CampaignActivity_Contacts - To revert: update
EntityRelationshipRelationships set RelationshipId = ''' +
CONVERT(VARCHAR(255), @WrongRelationshipId) + ''' where
EntityRelationshipRelationshipsRowId = ''' + CONVERT(VARCHAR(255), @WrongEntityRelationshipRelationshipId)
+ '''';

update EntityRelationshipRelationships 

set RelationshipId = @CorrectRelationshipId 

where EntityRelationshipId = @EntityRelationshipId

and RelationshipId not in (@CorrectRelationshipId,
@RelationshipIdBulkOperationLogs, @RelationshipIdCampaignActivityLogs);

SELECT @@ROWCOUNT

UPDATE DependencyBase

SET DependentComponentNodeId =
@CorrectRelationshipDependencyNodeIdContactForCA

WHERE RequiredComponentNodeId = (SELECT DependencyNodeId FROM
DependencyNodeBase WHERE ObjectId =
@EntityRelationshipsRelationshipIdContactForCA)

AND DependentComponentNodeId =
@WrongRelationshipDependencyNodeIdContactForCA

SELECT @@ROWCOUNT

set @FixesApplied = @FixesApplied + 1

end

else

PRINT 'FAILED to fix CampaignActivity_Contacts';

IF @FixesApplied = 6

PRINT 'EXECUTION SUCCEEDED - Please keep the printed revert statements
in case the fix needs to be reverted.'

ELSE

PRINT 'EXECUTION FAILED - This org could not be fully fixed
automatically and needs to be analyzed by dev if the issue persists after 24h.
Please raise an ICM for it. Please keep the printed revert statements in case
the fix needs to be reverted.'

    COMMIT TRAN t1

END TRY

BEGIN CATCH

    ROLLBACK TRAN t1

    PRINT 'EXECUTION FAILED :' +
ERROR_MESSAGE()

END CATCH

Script Sonrası İşlem

Script başarıyla tamamlandıktan sonra SQL Server Management Studio üzerindeki Messages alanı kontrol edilmelidir.

Tüm düzeltmeler başarılı şekilde uygulanmışsa:

EXECUTION SUCCEEDED

mesajı görüntülenecektir.

Script aynı zamanda yaptığı değişikliklerin geri alınabilmesi için revert sorgularını da çıktı olarak üretmektedir. Olası bir geri dönüş ihtiyacına karşı bu çıktıların saklanması önerilir.

SQL işlemi tamamlandıktan sonra CRM sunucusunda aşağıdaki komut çalıştırılmalıdır bir den fazla frontend sunucu var ise hepside çalıştırılması gerekmektedir:

iisreset

IISRESET tamamlandıktan sonra Dynamics 365 CRM’e tekrar giriş yapılarak hata alınan form açılmalı ve Sub-Grid ekleme işlemi yeniden denenmelidir.

Bu işlemler sonrasında metadata relationship ve dependency kayıtları düzeltilmiş ve CRM uygulama katmanındaki metadata cache’i yenilenmiş olacaktır.


Share this content:

Yorum gönder