locked
create a plugin to validate the Driver Licence Number .SHould be enter in proper formate and if already exist then display the message RRS feed

  • Question

  • create a plugin to validate the Driver Licence Number .

    SHould be enter in proper formate and if already exist then display the message

    Thursday, September 19, 2013 7:05 PM

All replies

  • Do you have a specific question? What have you done so far?

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Thursday, September 19, 2013 9:24 PM
    Moderator
  • \thank you for reply

    yes when a user enter driver no or a specific string in specific format for example AS123456 s

    if the format is not valid  in AS123456s then it show a message  not valid format error

    if its validated then it check against the already stored  data for example  AS123456s in the  database if exist show message Already exist

    thank you

    Friday, September 20, 2013 6:15 AM
  •  

    Hi ,

     1 * ) You can use duplicate detection rule find already license number exist in that string field.

     2 *) If you are going to write as a plugin weather already license no exist meas use retrieve multiple method .

    Eg : 
    
                        QueryExpression Contact = new QueryExpression { EntityName = "Schema Name", ColumnSet = new ColumnSet("field schema name") };
                        Contact.Criteria.AddCondition("field schema name", ConditionOperator.Equal, "AS123456s");
                        EntityCollection ContactRetrieve = service.RetrieveMultiple(Contact);

    You can get the License no field run time and pass into the parameter.



      3*) To validate Driving license no you can use java script. 

    Or you can do with plugin. 

    have a look at bellow link

    drivers license number validation regex

    Friday, September 20, 2013 6:30 AM
  • Hi,

    You have two option for this.

    - JavaScript.

    Write JavaScript that will check the format of the text entered and abort the save operation. us below code to abort the save operation.

    Xrm.Page.context.getEventArgs().preventDefault();

    - Validation Plugin.

    Write Pre Operation Plugin that will validate the Format and existence of with same license.

    You can throw an error message after validation in plugin.

    Thanks!

    Friday, September 20, 2013 6:03 PM
  • Hi there thanks for the reply .I am new to Crm java script and plugin can you email me the plugin logic and javascript crmguy100@outlook.com please
    Saturday, September 21, 2013 3:33 AM
  • Hi there I have tried so far but dont knw if you please try this

    using System;
    using System.ServiceModel;

    // Microsoft Dynamics CRM namespace(s)
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using System.Text.RegularExpressions;

    namespace Microsoft.Crm.Sdk.Samples
    {
        public class FollowupPlugin : IPlugin
        {

            public void Execute(IServiceProvider serviceProvider)
            {
                //Extract the tracing service for use in debugging sandboxed plug-ins.
                ITracingService tracingService =
                    (ITracingService)serviceProvider.GetService(typeof(ITracingService));

                // Obtain the execution context from the service provider.
                IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationService _service = factory.CreateOrganizationService(context.UserId);

                // The InputParameters collection contains all the data passed in the message request.
                try

                {


                if (context.InputParameters.Contains("Target") &&
                 context.InputParameters["Target"] is Entity)
                {
                    // Obtain the target entity from the input parameters.
                    Entity Contact = context.InputParameters["Target"] as Entity;

                    // Verify that the target entity represents an account.
                    // If not, this plug-in was not registered correctly.
                    if (Contact.LogicalName = "contact")
                {

                        //Entity contact = new Entity("contact");
                        Regex regexObj = new Regex(@"^(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)(?:[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z])(?:\s*\d\s*){6}([A-D]|\s)$");
                        QueryExpression Contact = new QueryExpression { EntityName = "contact", ColumnSet = new ColumnSet("nino") };
                        Contact.Criteria.AddCondition("nino", ConditionOperator.Equal, regexObj);
                        //Match match = Regex.Match("nino", regexObj, RegexOptions.IgnoreCase);
                        EntityCollection ContactRetrieve = _service.RetrieveMultiple(Contact);
                    }

                }

                }
                catch (InvalidPluginExecutionException)
                {
                    throw;
                }
                catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An FaultException occurred in the OnCreatePluginTest plug-in.", ex);
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException("An Exception occurred in the OnCreatePluginTest plug-in.", ex);
                }


            }


        }
    }

                                   
    Saturday, September 21, 2013 10:46 PM