locked
CRM 2016: In Plugins, how to set values on Create Event, Pre-Validation stage 10 RRS feed

  • Question

  • CRM 2016: In Plugins, how to set values on Create Event, Pre-Validation stage 10

    We have a situation where we need to SET and Clear values of a record before Create operation complete in the Plugin.


    Madhu M.

    Thursday, November 3, 2016 4:40 AM

Answers

  • Instead of setting NULL value to the field. I have tried to remove the fields from the context. Below is the sample code that I have used in the plugin

    ((Entity)(context.InputParameters["Target"])).Attributes.Remove("xxxxxxxxx");
    


    Madhu M.

    • Marked as answer by Madhu_M Monday, November 7, 2016 10:42 PM
    Monday, November 7, 2016 10:41 PM

All replies

  • You can do this by modifying the attributes in the Target InputParameter. This will affect the data that is written to CRM

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, November 3, 2016 12:21 PM
    Moderator
  • I am trying to find how to clear the values in Plugin execution context. appreciate if you could share any sample snippet on this.

    Madhu M.

    Thursday, November 3, 2016 3:46 PM
  • I have used the below code to clear the value in the context. it is working only for Admins or who have access to the (Encrypted)Field Level Security field and clearing the respective value;However other users are not able to clear(Null)the value in the context.

    Even I have tried running the plugin step with different (Admin) in credentials. Still it is giving error other non-Admin users.

    While debugging I found context.userId and context.Initiatinguserid running with same GUID. I am not sure why It is showing same GUID even I am running in different credentials

    if ((EntityReference)((Entity)context.InputParameters["Target"]).Attributes["new_conAccount"] != null)
    {
       ((Entity)context.InputParameters["Target"]).Attributes["new_conAcocunt"] = null;
    }



    Madhu M.


    • Edited by Madhu_M Friday, November 4, 2016 8:27 AM
    Friday, November 4, 2016 3:03 AM
  • Hi Madhu,

    Have you registered your plugin to run in 'System Admin' context in plugin registration tool?If not then please select.

    OR

    Change CRM service to run in SYSTEM context in plugin like below.pass 'null' while creating service instance.

          // Obtain the organization service reference.
                        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                        IOrganizationService service = serviceFactory.CreateOrganizationService(null);

    Hope it helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Sunday, November 6, 2016 1:07 AM
  • Thanks for your response. Run in Context  is a different from the user who is initiatinguser; however while debugging I see userid and initiatinguserid is same. below is the screenshot.


    Madhu M.

    Sunday, November 6, 2016 1:22 AM
  • Instead of setting NULL value to the field. I have tried to remove the fields from the context. Below is the sample code that I have used in the plugin

    ((Entity)(context.InputParameters["Target"])).Attributes.Remove("xxxxxxxxx");
    


    Madhu M.

    • Marked as answer by Madhu_M Monday, November 7, 2016 10:42 PM
    Monday, November 7, 2016 10:41 PM