-
So I'm trying to use Sql4Cds.Engine as a platform for doing pre/post install actions for a MS package, foundations are in which is pretty good, but I've it an issue with trying to enable Activity feeds for entities. I was hoping the script below would be good: update msdyn_postconfig set
statecode=0,
statuscode=1
where
statecode=1 and
msdyn_entityname in ('cr815_newtable')
OPTION (MAXDOP 1, USE HINT('BATCH_SIZE_1')) I have had previous where it would initially error due to updates in batches, but with MAXDOP and BATCH_SIZE_1, the error has transformed to:
Checking the front end, it does let you activate the Post Config record, but it does so via a SetStateRequest, rather than the UpdateRequest (and the state/statuscode match). I haven't managed individually to get execute SetState working either :(. Any thoughts/ideas? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I've seen this before when a plugin is trying to make metadata changes automatically based on the data changes. If you can show me a simple C# app that executes the SDK messages that you need to get this to work, I can try to figure out how to express those in SQL 4 CDS. |
Beta Was this translation helpful? Give feedback.
-
This is what we currently have, but the main bit is the Execute of the SetStateRequest. extension.PackageLog.Log("Retrieving Activity Feeds to Activate");
QueryExpression inactiveEntityQuery = new QueryExpression("msdyn_postconfig");
inactiveEntityQuery.ColumnSet = new ColumnSet("msdyn_entityname");
inactiveEntityQuery.Criteria = new FilterExpression(LogicalOperator.And);
inactiveEntityQuery.Criteria.AddCondition("statecode", ConditionOperator.Equal, 1); // Inactive
inactiveEntityQuery.Criteria.AddCondition("msdyn_entityname", ConditionOperator.In, entities.Cast<object>().ToArray());
EntityCollection inactiveEntities = extension.CrmSvc.RetrieveMultiple(inactiveEntityQuery);
extension.PackageLog.Log($"{inactiveEntities.Entities.Count} Entities to Enable");
// Activate the Inactive Ones
foreach (var currentEntity in inactiveEntities.Entities)
{
extension.PackageLog.Log($"Activating {currentEntity.GetAttributeValue<string>("msdyn_entityname")}");
extension.CreateProgressItem($"Activating Activity Feed for {currentEntity.GetAttributeValue<string>("msdyn_entityname")}", PDStage.Unknown);
extension.CrmSvc.Execute(new SetStateRequest()
{
EntityMoniker = currentEntity.ToEntityReference(),
State = new OptionSetValue(0),
Status = new OptionSetValue(-1)
});
extension.RaiseUpdateEvent($"Activating Activity Feed for {currentEntity.GetAttributeValue<string>("msdyn_entityname")}", ProgressPanelItemStatus.Complete, PDStage.Unknown);
} |
Beta Was this translation helpful? Give feedback.
I'm working on including this in the next version. It should also be possible to execute
SetState
using the stored procedure syntax but there's a bug passing in the OptionSetValue parameters which I'll try to fix at the same time. The new syntax will be: