locked
Message box in Unit Group entity from plugin. RRS feed

  • Question

  •  

    Hi ,

     

    Here is my business logic.

     

    When i Open 'Unit group' from product catalog 'unit name'  value  has to be "Tonnes". ( need to force user to put this value)

     

    To achieve this i have written plugin on precreate of "Unit group" entity and than i compare

    string "Tonnes" with whatever user has entered.

    Now, how should i show message box to user if he/she doesn't enter value "Tonnes"...

    as Unit group and Unit entity both doesn't have Form so i can't write it on java script.(onsave event or onchange)

     

    That's why i wrote plugin which will fire once user will put unit group name and unit name and then press OK button.

    I assumed messagebox.show is for windows application and not for web application like CRM 4.0.

     

    in short i want to do something  like this

    {

     

    if (string.Compare("Tonnes", Base_Unit.Value,true)== 1)

    {

    MessageBox.Show("You can only enter 'Tonnes' as unit");

     

    }

     

    Many thanks in advance

     

    -Him912

    Wednesday, October 29, 2008 5:03 AM

Answers

All replies

  • The only way to display a message form a plugin is to throw an InvalidPluginExecutionException exception within the plugin. See http://msdn.microsoft.com/en-gb/library/cc151090.aspx

     

     

    Wednesday, October 29, 2008 9:52 PM
    Moderator
  • Thanks David. I will try the way you have suggested.

     

    Thursday, October 30, 2008 12:33 AM
  • Hi Mate,

     

    again i need your help.

     

    Following is my code which is class file and registered for Create message in plugin registration tool.

    my business logic is same as i have described before.

     

    because plugin is meant be written for precreate of entity, i guess it's not generating any guid for it but

    program is searching for primary key(guid). 

     

    My question is how can retrieve primary key of entity before i create entity and my business login doesn't alllow me

    to create entity if someone put wrong string (i.e other than 'Tonnes') in base unit name of unit name entity.

     

    again many thanks in advance.

     

    ================================== Class File ==========================================

     public void CheckUnit(ICrmService service, DynamicEntity DETarget)
            {
              
                TargetRetrieveDynamic targetDE = new TargetRetrieveDynamic();
                targetDE.EntityName = EntityName.uomschedule.ToString();
               // targetDE.EntityId = uomscheduleid;
                                                              
                RetrieveRequest retrieve = new RetrieveRequest();
                retrieve.Target = targetDE;
                retrieve.ColumnSet = new AllColumns();
                retrieve.ReturnDynamicEntities = true;
                                      
                RetrieveResponse response = (RetrieveResponse) service.Execute(retrieve);

                DynamicEntity de = (DynamicEntity) response.BusinessEntity;
               
                 if (de.Properties["baseuomname"].ToString() != "Tonnes".ToString())
                {
                    throw new InvalidPluginExecutionException("You can only enter 'Tonnes'as a unit");
                }
            } //end of function
        }
    =============================End of class file =====================================

    When i execute this i get error as follows:

     

     

    Event Type: Error
    Event Source: MSCRMWebService
    Event Category: None
    Event ID: 18176
    Date:  31/10/2008
    Time:  1:33:03 PM
    User:  N/A
    Computer: SNAPDEVSERVER
    Description:
    Web Service Plug-in failed in OrganizationId: 14091b76-feb1-47e8-836b-05c56c75b553; SdkMessageProcessingStepId: 20eacb25-e6a6-dd11-90fe-0003ff4e3f97; EntityName: uomschedule; Stage: 10; MessageName: Create; AssemblyName: Test.UnitPrecreate, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4e736fc0041d9bd4; ClassName: Test.UnitPrecreate; Exception: Unhandled Exception: System.Web.Services.Protocols.SoapException: Server was unable to process request.
    Detail: <detail><error>
      <code>0x80040217</code>
      <description>uomschedule With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist</description>
      <type>Platform</type>
    </error></detail>
       at Microsoft.Crm.Extensibility.SdkTypeProxyCrmServiceWrapper.InternalInvoke(MethodInfo methodInfo, Object[] parameters)
       at Microsoft.Crm.Extensibility.SdkTypeProxyCrmServiceWrapper.Execute(Object request)
       at Test.Unitgroup.CheckUnit(ICrmService service, DynamicEntity DETarget)
       at Test.UnitPrecreate.Execute(IPluginExecutionContext context)
       at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
    .==============================================================================

     

    Thanks David.
    Friday, October 31, 2008 4:28 AM