Posts

Showing posts from April, 2021

How to get Shared variable declared in PreValidate operation in D365 plug in

  Suppose when we declared a shared variable in PreValidate operation and we are trying to get it using Context.SharedVarible[“yourKey”] in PreOperation and PostOperation. It will give error as below.   The given key was not present on the dictionary.   We need to read it using below syntax in both preOperation & PostOperation   Var myVariable = context.ParentContext.SharedVariables["MyVariable"].ToString()

PreValidate plug in example

Image
PreValidation plug in example: One of the most common interview question that never forgotten by any one and of course in Realtime this will rarely used. When we want to get no of child records when we are deleting the main/parent record then we can use PreValidation stage to get the count.   As some one thinks at very first time, why can’t we get the count in PreOperation stage. Because this will be in the same execution and we will not get the record count and by the stage it reaches to 20(PreOperation) all the child records gets deleted as per the relationship behavior.   So we need to register our plug in in PreValidaton. Below is the sample example to get the count of child records when we register the plug in in Delete message.   if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)             {        ...