This is how to get only changed data
Get changed data
Xrm.Page.data.entity.getDataXml()
CRM 2011 JS: Get data in fields that have changed on form using
CRM 2011 JS: Hide and Show tab
This is how to hide and show tab
Hiding tab
Xrm.Page.ui.tabs.get(tabindex).setVisible(false);
or
Xrm.Page.ui.tabs.get("tabname").setVisible(false);
Showing tab
Xrm.Page.ui.tabs.get(tabindex).setVisible(true);
or
Xrm.Page.ui.tabs.get("tabname").setVisible(true);
CRM 2011 JS: SOAP Request Example for new_entityname
/*
The following is the SOAP Request Example for new_entityname
*/
function SOAPReqbyExample() {
var GUIDvalue = Xrm.Page.data.entity.getId();
//var name = Xrm.Page.getattrib(
if (GUIDvalue != null) {
var varh = GUIDvalue;
}
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
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>" +
"<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entity xsi:type='new_entityname'>" +
"<new_fieldname>" + varh + "</new_fieldname>" +
"</entity>" +
"</Create>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
alert("Created");
// Capture the result
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
}
CRM 2011 JS: Hide and Show section using javascript in CRM 2011
// Hide and Show section using javascript in CRM 2011
// Hiding Section
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex).setVisible(false);
or
Xrm.Page.ui.tabs.get(tabIndex).sections.get("sectionName").setVisible(false);
// Showing Section
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex).setVisible(true);
or
Xrm.Page.ui.tabs.get(tabIndex).sections.get("sectionName").setVisible(true);
CRM 2011 JS: Expand / Collapse tab using javascript in CRM 2011
// Expand / Collapse tab example
// Expand tab
Xrm.Page.ui.tabs.get("tabname").setDisplayState('expanded');
//Collapse tab
Xrm.Page.ui.tabs.get("tabname").setDisplayState('collapsed');
CRM 2011 JS: Open popup window using javascript in CRM 2011
This is how to open popup window
//CRM function to open a Popup window
var url = "http://crm2011:5555/test/main.aspx?etn=account&pagetype=entityrecord";
var name = "popup";
var width = 800;
var height = 600;
var feature = "status=1";
openStdWin(url, name, width, height, feature);
CRM 2011 JS: Soap XML Retrieve using javascript in CRM 2011
Soap XML Retrieve using javascript in CRM 2011
Use Soap XML Retrieve web service
http://schemas.microsoft.com/crm/2007/WebServices/Retrieve
This javascript code is fetching Account entity address into using Contact parentcustomerid attribute and filling in Contact address fields
Soap XML retrieve
if (Xrm.Page.getAttribute("parentcustomerid").getValue() != null) {
//acount guid no
var parentcustomerID = Xrm.Page.data.entity.attributes.get("parentcustomerid").getValue()[0].id;
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'>" +
GenerateAuthenticationHeader() +
"<soap:Body>" +
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entityName>account</entityName>" +
"<id>" + parentcustomerID + "</id>" +
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
"<q1:Attribute>address1_addresstypecode</q1:Attribute>" +
"<q1:Attribute>address1_name</q1:Attribute>" +
"<q1:Attribute>address1_line1</q1:Attribute>" +
"<q1:Attribute>address1_line2</q1:Attribute>" +
"<q1:Attribute>address1_city</q1:Attribute>" +
"<q1:Attribute>address1_stateorprovince</q1:Attribute>" +
"<q1:Attribute>address1_postalcode</q1:Attribute>" +
"<q1:Attribute>address1_country</q1:Attribute>" +
"<q1:Attribute>address1_telephone1</q1:Attribute>" +
"</q1:Attributes>" +
"</columnSet>" +
"</Retrieve>" +
"</soap:Body>" +
"</soap:Envelope>";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
if (resultXml.selectSingleNode("//q1:address1_addresstypecode") != null) { Xrm.Page.getAttribute("address1_addresstypecode").setValue(resultXml.selectSingleNode("//q1:address1_addresstypecode").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_addresstypecode").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_name") != null) {
Xrm.Page.getAttribute("address1_name").setValue(resultXml.selectSingleNode("//q1:address1_name").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_name").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_line1") != null) {
Xrm.Page.getAttribute("address1_line1").setValue(resultXml.selectSingleNode("//q1:address1_line1").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_line1").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_line2") != null) {
Xrm.Page.getAttribute("address1_line2").setValue(resultXml.selectSingleNode("//q1:address1_line2").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_line2").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_city") != null) {
Xrm.Page.getAttribute("address1_city").setValue(resultXml.selectSingleNode("//q1:address1_city").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_city").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_stateorprovince") != null) {
Xrm.Page.getAttribute("address1_stateorprovince").setValue(resultXml.selectSingleNode("//q1:address1_stateorprovince").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_stateorprovince").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_postalcode") != null) {
Xrm.Page.getAttribute("address1_postalcode").setValue(resultXml.selectSingleNode("//q1:address1_postalcode").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_postalcode").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_country") != null) {
Xrm.Page.getAttribute("address1_country").setValue(resultXml.selectSingleNode("//q1:address1_country").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_country").setValue(null);
}
}
CRM 2011 JS: Soap XML RetrieveMultiple using javascript
Use Soap XML Retrieve web service
This javascript code is fetching all contact have same value as custom attribute value
Soap XML retrievemutliple
var contactname = Xrm.Page.getAttribute("new_contact").getValue();
var authenticationHeader = GenerateAuthenticationHeader();
if (contactname != null && contactname != "undefined") {
var Accountxml = "" + "<?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>contact</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>address1_city</q1:Attribute>" +
" <q1:Attribute>address1_stateorprovince</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:PageInfo>" +
" <q1:PageNumber>1</q1:PageNumber>" +
" <q1:Count>1</q1:Count>" +
" </q1:PageInfo>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>firstname</q1:AttributeName>" +
" <q1:Operator>Equal</q1:Operator>" +
" <q1:Values>" +
" <q1:Value xsi:type=\"xsd:string\">" + contactname + "</q1:Value>" +
" </q1:Values>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </query>" +
" </RetrieveMultiple>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
// Create an instance of an XMLHTTP object.
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", Accountxml.length
);
// Send the XMLHttp request.
xmlHttpRequest.send(Accountxml);
// Capture the XMLHttp response in XML format.
var resultXml = xmlHttpRequest.responseXML;
if (resultXml.selectSingleNode("//q1:address1_city") != null) { Xrm.Page.getAttribute("address1_city").setValue(resultXml.selectSingleNode("//q1:address1_city").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_city").setValue(null);
}
if (resultXml.selectSingleNode("//q1:address1_stateorprovince") != null) { Xrm.Page.getAttribute("address1_stateorprovince").setValue(resultXml.selectSingleNode("//q1:address1_stateorprovince").nodeTypedValue);
}
else {
Xrm.Page.getAttribute("address1_stateorprovince").setValue(null);
}
}
CRM 2011 CS: Retrieve the schedule of a system user
/* Retrive The Schedule of Current User */
using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
serverConfig.HomeRealmUri,
serverConfig.Credentials,
serverConfig.DeviceCredentials))
{
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
// Get the current user's information.
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);
// Retrieve the schedule of the current user.
QueryScheduleRequest scheduleRequest = new QueryScheduleRequest
{
ResourceId = userResponse.UserId,
Start = DateTime.Now,
End = DateTime.Today.AddDays(7),
TimeCodes = new TimeCode[] { TimeCode.Available }
};
QueryScheduleResponse scheduleResponse = (QueryScheduleResponse)_serviceProxy.Execute(scheduleRequest);
}
CRM 2011 CS: Retrieve the schedule of Multiple users
using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
serverConfig.HomeRealmUri,
serverConfig.Credentials,
serverConfig.DeviceCredentials))
{
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
// Get the current user's information.
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);
Guid _currentUserId = userResponse.UserId;
// Create another user
Guid _otherUserId = new Guid("0a4252a0-7e70-11d0-a5d6-28db04c10000");
// Retrieve the schedule of the current and the other user.
QueryMultipleSchedulesRequest scheduleRequest = new QueryMultipleSchedulesRequest();
scheduleRequest.ResourceIds = new Guid[2];
scheduleRequest.ResourceIds[0] = _currentUserId;
scheduleRequest.ResourceIds[1] = _otherUserId;
scheduleRequest.Start = DateTime.Now;
scheduleRequest.End = DateTime.Today.AddDays(7);
scheduleRequest.TimeCodes = new TimeCode[] { TimeCode.Available };
QueryMultipleSchedulesResponse scheduleResponse = (QueryMultipleSchedulesResponse)_serviceProxy.Execute(scheduleRequest);
}