Ajax in CRM  
Author Message

PostPosted: ISV Open Discussions, Ajax in CRM Top

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 ^_^.

Microsoft ISV Community Center Forums1  
Mattias Sjogren

PostPosted: ISV Open Discussions, Ajax in CRM Top

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.


PostPosted: ISV Open Discussions, Ajax in CRM Top

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.

MS ISV Buddy Team

PostPosted: ISV Open Discussions, Ajax in CRM Top

Kartini: We passed your issue to the Microsoft support engineers. Here is what they suggest:

Have you tried setting the number at the OnChange event

This way you assign the next number before it is saved to the database.

Here is another suggestion:


This event does not correspond to the standard OnSubmit event exposed by DHTML. It is fired when a user presses the Save or Save and Close button on the form. The event is fired whether the data in the form has been modified or not.

Validating data is a common reason to use the OnSave event. The OnSave event can cancel the save before it is sent back to the server.

If the following code is included, the Save is cancelled.

event.returnValue = false;


PostPosted: ISV Open Discussions, Ajax in CRM Top

I think your problem is that you are making an asynchronous call to your .aspx page. Try making it synchronous:

xmlHttp.open("GET",url,false) ;

Mohamed sobhy

PostPosted: ISV Open Discussions, Ajax in CRM Top

Read this blog entry I think it has the answer to your question