locked
Confirm Window In MSCRM 3.0 RRS feed

  • Question

  • Dear All,

    I'm Beginner in MSCRM and the coding.

    I want to add confirm windows before save the Order. So.. when the user try to Save order, the system should check value "CustRef" (Customer Reference) attribute is already exist or not. If the value of CustRef already input before so... the system will ask the user like confirm windows : "the value already exist in Database, Do You want Save again ? " with "Ok" button to continue (save data) Or "Cancel" button to back again the Order form (but not save the data yet).

    is it better create in WebService or in WebApplication ? i already create code in webservice but i'm stuck with the confirm windows, i dont know the code to create confirm windows with ok or cancel button, does anybody can give the direction ?

    Thanks

     

    Best Regards,

    Anyan

     

     

    Wednesday, November 10, 2010 3:24 AM

Answers

  • Hi Anyan,

    As a said before you can call webservices through javascript.

    hava a look at this sample

    http://blogs.msdn.com/b/arash/archive/2006/08/29/729320.aspx

    if the custref does exist

    var result = confirm(" Custref already exist in the app, Would you like to create it anyway");

    if (result!=true)

    {

    event.returnValue = false;

    }

    if the user press cancel. the above code will skip the save event. if the answer will yes, the crm will execute the save process as usual.

     

    Regards,

     

     


    Amreek singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com
    • Proposed as answer by Amreek Singh Sunday, November 21, 2010 1:46 AM
    • Marked as answer by Jim Glass Jr Monday, November 22, 2010 6:45 PM
    Sunday, November 21, 2010 1:46 AM

All replies

  • If you just want to check if the Cust Ref value already exists on another order you can use Duplicate Detection. Check it out under Settings Area in CRM.
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Check out the CRM 4 to CRM 2011 JavaScript Converter Tool
    CRM Forum Guidance on how to Help Us Help You
    Wednesday, November 10, 2010 11:00 PM
    Moderator
  • dear Rhettclinton

    I can't find Duplicate detection under setting Area, for your info I'm using MS CRM 3.0, are u sure in MS CRM 3.0 have the duplicate Detection ? can u show me how to find it ?

    This is setting area MS CRM 3.0 :

    Setting Area
    Thursday, November 11, 2010 3:39 AM
  • You can access the crm webservices on client side (javascript). On save event of form the check using webservice if the custref exist. if it does use the confirm function of javascript to get the answer, if the answer is yes, save the record and if the answer is cancel or no. dont save the record.

    There are lot of articles on web on how to use webservices in javascript.

    http://blogs.msdn.com/b/arash/archive/2006/08/29/729320.aspx

     

    I hope it helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com
    Thursday, November 11, 2010 5:21 AM
  • You can access the crm webservices on client side (javascript). On save event of the check using webservice if the custref exist. if it does use the confirm function of javascript to get the answer, if the answer is yes, save the record and if the answer is cancel or no. dont save the record.

    There are lot of articles on web on how to use webservices in javascript.

    http://blogs.msdn.com/b/arash/archive/2006/08/29/729320.aspx

     

    I hope it helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com

     

    Dear Amreek Singh,


    I can check Cust Ref from the Webservice is already exist or not, with the script :

    [WebMethod]
    public void HandlePreCreate(Guid userId, Guid bizUnitId, ref string entityXml, ref string   errorMessage)
    {                   
                // declare crm service
                CrmService crm = new CrmService();
                crm.Credentials = CredentialCache.DefaultCredentials;
                crm.CallerIdValue = new CallerId();
                crm.CallerIdValue.CallerGuid = userId;

                AutoNumbering an = new AutoNumbering();
               
                try
                {
                    // deserialize xml into dynamic entity object
                    DynamicEntity de = DynamicEntityHelper.DeserializeIntoDynamicEntity(entityXml);
                    //helper variable
                    ColumnSet cols = new ColumnSet();
                    BusinessEntity entity;

           
           //Begin Validasi Cust Ref           
                    StringProperty custRefProp = (StringProperty)DynamicEntityHelper.getDynamicEntityProp(de, "new_customerref");
                     bool result = false;

                SqlConnection conn = new  SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);

                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select new_customerref from SalesOrderExtensionBase where new_customerref = '" + custRefProp.Value + "'";

                try
                {
                    conn.Open();

                    cmd.Connection = conn;
                    SqlDataReader rdr = cmd.ExecuteReader();

                    if (rdr.Read())
                    {
                        if (!rdr.IsDBNull(0))
                            errorMessage = "Cust Ref Already Exists";     // The Alert Only Ok Button          
                    }

                    rdr.Close();
                }
                catch (Exception exc)
                {
                    //lblMessage.Text = exc.ToString();     
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                        conn.Close();            
                    conn.Dispose();
                    cmd.Dispose();
                }

     

    From the error message only have one button (ok Button) and it always back to the form.

    Can u help me how to know the "Error message" value  to input in crm onsave in form properties ?


    Monday, November 15, 2010 9:41 AM
  • Hi

    you are passing the errormsg by ref  so check the value of the variable.

    I would say use javascript debugging.

    put the follwing line at the top of form load event of the form.

    debugger;

    also Open the Internet Explorer settings and select the Advanced tab. In the list of available options find the "Disable Script Debugging (Internet Explorer)" setting and make sure it's unchecked.

    check if your webservice is working properly.

    One last thing.

    I would rather return a string from the function instead of void. this string can contain result of the webmethod as well as error messages.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com
    Monday, November 15, 2010 11:26 AM
  • Hi

    you are passing the errormsg by ref  so check the value of the variable.

    I would say use javascript debugging.

    put the follwing line at the top of form load event of the form.

    debugger;

    also Open the Internet Explorer settings and select the Advanced tab. In the list of available options find the "Disable Script Debugging (Internet Explorer)" setting and make sure it's unchecked.

    check if your webservice is working properly.

    One last thing.

    I would rather return a string from the function instead of void. this string can contain result of the webmethod as well as error messages.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com


    Hi Amreek i dit put script (debugger) on form load event of the form and i also uncheck disable script in internet explorer setting after that i try to save new order (with same custref) but theres nothing happened.

    I got 2 solution that i want to try but I confuse

    1. how to add "confirm" javascript language in C#, i would like to add in my script

    if (rdr.Read())
    {
            if (!rdr.IsDBNull(0))
                errorMessage = "Cust Ref Already Exists";     ===>>  The Confirm javascript          
     }

     

    2. How pass custref value from webservice to CRM?  i want to check custref value ONSave event on Order Form Properties

     

     

    Thank you

    Friday, November 19, 2010 9:20 AM
  • Hi Anyan,

    As a said before you can call webservices through javascript.

    hava a look at this sample

    http://blogs.msdn.com/b/arash/archive/2006/08/29/729320.aspx

    if the custref does exist

    var result = confirm(" Custref already exist in the app, Would you like to create it anyway");

    if (result!=true)

    {

    event.returnValue = false;

    }

    if the user press cancel. the above code will skip the save event. if the answer will yes, the crm will execute the save process as usual.

     

    Regards,

     

     


    Amreek singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com
    • Proposed as answer by Amreek Singh Sunday, November 21, 2010 1:46 AM
    • Marked as answer by Jim Glass Jr Monday, November 22, 2010 6:45 PM
    Sunday, November 21, 2010 1:46 AM