Hi, i have a problem in CRM. I have a custom field named "new_number" and this field is disabled in form Order. I want to fill this field with autonumbering system which it must working with CRM Web Services, so i make a code that will return the new_number data into the field new_number in CRM Order form. To do that, i think i must working with AJAX (for example if the last record of new_number is A0001, then ajax will return A0002), where i can write my ajax code in Order Form Properties (onSave function at Save button). This is my AJAX code :
function OnSave() { var xmlHttp = null; if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest(); else if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") ;
if (xmlHttp == null) { alert ("Browser does not support HTTP Request") ; return ; }
var url = "http://crm:81/OrderNo/getOrderNo.aspx"; xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState==4) crmForm.all.new_limasorderno.DataValue=xmlHttp.responseXML.getElementsByTagName("orderid")[0].firstChild.data; } xmlHttp.open("GET",url,true) ; xmlHttp.send(null) ; }
But in the fact, the CRM will do save action first, and then fill the new_number field, so the new_number value doesn't filled into the database. Anyone can help me to solve this problem? Thx before ^_^.
Kartini
Have you considered putting the code in the OnLoad event instead? You can check whether it's a create or update form and only run the code for new orders.
I would probably implement this as a server side callout, however.
Mattias, C# MVP
Mattias Sjögren
I think it can't be put in OnLoad, because the autonumbering system is depend to the picklist new_ordertype value. For example the new_ordertype picklist have 2 value : Free Trial and Full Version. The code for the Free Trial is start with FT0001, and the code for Full Version is start with FV0001. So, the ajax can't put in onLoad, but must onSave function.