locked
Auto Generated Order ID Masking RRS feed

  • Question

  • I just generated my first order (Test), and it is: ORD-01001-N1Z3D9

    Can I change the way automated ID numbers are generated?

    I would prefer to keep it simpler, and Put 2 Letters at the beginning.

    It would be very cool to change those two letters depending on the customer's status.. (wholesale, retail, etc)

    Thanks!


    CRM 2011 Beginner - All Help Appreciated.
    Thursday, June 9, 2011 5:20 PM

All replies

  • Hello,

    Go to Settings - Administration - Auto-Numbering - change prefix and click "OK".


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, June 9, 2011 7:58 PM
    Moderator
  • Privyet Andriy,

     

    Spiceeba.

     

    That seemed easy enough... I wanted the prefix to be GC-ORD, but it only allows 3 characters. I imagine somewhere I can change the field length....

    And I can only reduce the size of the suffix. I do not even want a suffix.. unless there is some reason.

     

    Any ideas?


    CRM 2011 Beginner - All Help Appreciated.
    Thursday, June 9, 2011 8:07 PM
  • I'm afraid that this is out-of-box functionality and you will have to follow it...
    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, June 9, 2011 8:37 PM
    Moderator
  • Hi, for your requirement you have to write the JavaScript on PageLoad event.

    the below code will help you out.

    if (crmForm.FormType == 1) {
        //START===AUTO INCREMENT NUMBERING
        //debugger;
        if (crmForm.all.OrderId.DataValue == null) {
            getIncrement();
            crmForm.all.OrderId.DataValue = null;
        }
        else {
            var OrderID= crmForm.all.OrderId.DataValue;
            var objOrderID= OrderID[0].id;
            getIncrement();
        }

        function getIncrement() {

            var authenticationHeader = GenerateAuthenticationHeader();
            var xml = "" +
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
            authenticationHeader +
            " <soap:Body>" +
            " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
            " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
            " <q1:EntityName>gms_paymentaccounting</q1:EntityName>" +
            " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
            " <q1:Attributes>" +
            " <q1:Attribute>gms_doc_actg_ln_no</q1:Attribute>" +
            " <q1:Attribute>gms_OrderID</q1:Attribute>" +
            " </q1:Attributes>" +
            " </q1:ColumnSet>" +
            " <q1:Distinct>false</q1:Distinct>" +
             "<q1:Orders>" +
             "<q1:Order>" +
             "<q1:AttributeName>gms_OrderID</q1:AttributeName>" +
             "<q1:OrderType>Descending</q1:OrderType>" +
             "</q1:Order>" +
             "</q1:Orders>" +

            " <q1:Criteria>" +
            " <q1:FilterOperator>And</q1:FilterOperator>" +
            " <q1:Conditions>" +
            " <q1:Condition>" +
            " <q1:AttributeName>gms_paymentrequestid</q1:AttributeName>" +
            " <q1:Operator>Like</q1:Operator>" +
            " <q1:Values>" +
            " <q1:Value xsi:type=\"xsd:string\">" +
            paymentrequestid +
            "</q1:Value>" +
            " </q1:Values>" +
            " </q1:Condition>" +
            " </q1:Conditions>" +
            " </q1:Criteria>" +

            " </query>" +
            " </RetrieveMultiple>" +
            " </soap:Body>" +
            "</soap:Envelope>" +
            "";

            //gms_paymentrequestid
            // Prepare the xmlHttpObject and send the request.
            var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
            xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
            xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
            xmlHttpRequest.send(xml);

            var resultXml = xmlHttpRequest.responseXML;
            //alert(resultXml.xml);

            //var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
            var maxAccNo = resultXml.selectNodes("//BusinessEntity/q1:gms_doc_actg_ln_no");
            if (maxAccNo.length > 0) {
                //alert('length of array: ' + maxAccNo.length );
                //alert('Max Acc No:' + maxAccNo[0].text);
                var val0 = parseInt(maxAccNo[0].text);
                // alert('again Max Acc No:' + val0);

                var val1 = "GC" + val0;

                //  alert ('Value' + val1 );
                crmForm.all.gms_doc_actg_ln_no.DataValue = val1;
            }
           

        }

    }

    let me know if you want anything.


    Thanks, - Israel Pradeep, - Software Engineer & PMP & B.I - Entrepreneur, - "If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"".
    Thursday, June 9, 2011 10:01 PM
  • Hello Israel,

    I'm afraid that your code will help experienced developer (but not to beginner, as it is written at signature of person who opened this thread). Following question will appear:

    1. What is OrderId field - I have no such field in SalesOrder entity.

    2. I tried your code and it doesn't work because you have a lot of customizations (like gms_paymentaccounting entity with custom fields and e.t.c.)

    3. Your script throws an error at line crmForm.all.gms_doc_actg_ln_no.DataValue = val1;//because order form doesn't contain such field.

     

    My suggestion - in the case you really want to help - post here solutions that will work without any additional actions or describe actions which must be performed to make this script or code work...


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, June 9, 2011 11:04 PM
    Moderator
  • Andriy & WD64,

    the above code was my requirement before. I just modified lightly and pasted here for his reference.

    Andriy, Yes you are correct, but the requirement is not from out of the box. So He need to write the code. For your questions:

    1. What is OrderId field - I have no such field in SalesOrder entity. I agree it should be SalesOrderID.

    2. I tried your code and it doesn't work because you have a lot of customizations (like gms_paymentaccounting entity with custom fields and e.t.c.)

    Here the gms_paymentaccountingmeans SalesOrderId

    3. Your script throws an error at line crmForm.all.gms_doc_actg_ln_no.DataValue = val1;//because order form doesn't contain such field.

    The gms_doc_actg_ln_no is the SalesOrderId.

     

    So this is the final one..... WD64- take this code and put into the OnLoad event of the form.

    if (crmForm.FormType == 1) {
        //START===AUTO INCREMENT NUMBERING
        //debugger;
        if (crmForm.all.SalesOrderId.DataValue == null) {
            getIncrement();
            crmForm.all.SalesOrderId.DataValue = null;
        }
        else {
            var OrderID= crmForm.all.SalesOrderId.DataValue;
            var objOrderID= OrderID[0].id;
            getIncrement();
        }

     

    function getIncrement() {

            var authenticationHeader = GenerateAuthenticationHeader();
            var xml = "" +
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
            authenticationHeader +
            " <soap:Body>" +
            " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
            " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
            " <q1:EntityName>SalesOrder</q1:EntityName>" +
            " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
            " <q1:Attributes>" +
            " <q1:Attribute>SalesOrderID</q1:Attribute>" +
            " </q1:Attributes>" +
            " </q1:ColumnSet>" +
            " <q1:Distinct>false</q1:Distinct>" +
            "<q1:Orders>" +
             "<q1:Order>" +
             "<q1:AttributeName>SalesOrderID</q1:AttributeName>" +
             "<q1:OrderType>Descending</q1:OrderType>" +
             "</q1:Order>" +
             "</q1:Orders>" +

     

            " <q1:Criteria>" +
            " <q1:FilterOperator>And</q1:FilterOperator>" +
            " <q1:Conditions>" +
            " <q1:Condition>" +
            " <q1:AttributeName>objOrderID</q1:AttributeName>" +
            " <q1:Operator>Like</q1:Operator>" +
            " <q1:Values>" +
            " <q1:Value xsi:type=\"xsd:string\">" +
            paymentrequestid +
            "</q1:Value>" +
            " </q1:Values>" +
            " </q1:Condition>" +
            " </q1:Conditions>" +
            " </q1:Criteria>" +
            " </query>" +
            " </RetrieveMultiple>" +
            " </soap:Body>" +
            "</soap:Envelope>" +
            "";

            //gms_paymentrequestid
            // Prepare the xmlHttpObject and send the request.
            var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
            xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
            xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
            xmlHttpRequest.send(xml);

            var resultXml = xmlHttpRequest.responseXML;
            //alert(resultXml.xml);

            //var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
            var maxAccNo = resultXml.selectNodes("//BusinessEntity/q1:SalesOrderID");

            if (maxAccNo.length > 0) {
                //alert('length of array: ' + maxAccNo.length );
                //alert('Max Acc No:' + maxAccNo[0].text);

                 var salersOrderId = maxAccNo[0].text;

                 var reqString = salersOrderId.substring(1,4);

                 var autoNumber = salersOrderId.substring(4,9);

                 reqString = "GC-" + reqString;

                 var val0 = parseInt(autoNumber) + 1;

                
                // alert('again Max Acc No:' + val0);

                var val1 =reqString + val0;

                //  alert ('Value' + val1 );
                crmForm.all.SalesOrderID.DataValue = val1;
            }
           

        }

    }

     

    WD64, the above code gives you the brief IDEA. Let me if you need any further JScript


    Thanks, - Israel Pradeep, - Software Engineer & PMP & B.I - Entrepreneur, - "If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"".
    Friday, June 10, 2011 12:15 AM
  • Are you sure that Sales Order form contains SalesOrderId attribute?

    I'm not sure. SalesOrderId is PK for SalesOrder entity and it is possible to get it only after creation of the record using crmForm.ObjectId but not crmForm.all.SalesOrderId.DataValue script, so your script would not work in any case.

     

    PS I have already wrote - you should not paste code here if it doesn't work. It would break the mind of customizer who will try to use it...


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Friday, June 10, 2011 12:22 AM
    Moderator
  • :) Great dedication to your work.

    It means he can use the PK of the form.

     


    Thanks, - Israel Pradeep, - Software Engineer & PMP & B.I - Entrepreneur, - "If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"".
    Friday, June 10, 2011 12:31 AM
  • It means he can use the PK of the form.

    In what way can he use PK? You should read SDK - http://technet.microsoft.com/en-us/library/cc150873.aspx There is written that crmForm.ObjectId is read-only. In what way it is possible to use GUID field (which is crmForm.ObjectId) to create autonumeration field?

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Friday, June 10, 2011 12:38 AM
    Moderator
  • If its Create Form then instead of PK, we can use the AlphaNumeric text field and it acts as Static field. In the above code if we delete the values parameter. then it returns the Max value of the field. from that we can hard code to get the value.

    Nice talking to you Andriy.

     


    Thanks, - Israel Pradeep, - Software Engineer & PMP & B.I - Entrepreneur, - "If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"".
    Friday, June 10, 2011 1:04 AM