Xrm.Page.getControl("new_fieldname").setDisabled(true);
Wednesday, 28 November 2012
Hide tab or field based on User roles in CRM 2011 using javascript
function UserHasRole(roleName) {
var serverUrl = Xrm.Page.context.getServerUrl();
var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
oDataEndpointUrl += "RoleSet?$top=1&$filter=Name eq '" + roleName + "'";
var service = GetRequestObject();
if (service != null)
{
service.open("GET",oDataEndpointUrl, false);
service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
service.setRequestHeader("Accept", "application/json,text/javascript, */*");
service.send(null);
var requestResults = eval('(' +service.responseText + ')').d;
if (requestResults != null && requestResults.results.length == 1)
{
var role = requestResults.results[0];
var id = role.RoleId;
//Get Current User Roles
var currentUserRoles = Xrm.Page.context.getUserRoles();
//Check whether current user roles has the role passed as argument
for (var i = 0; i < currentUserRoles.length;i++)
{
var userRole = currentUserRoles[i];
if (GuidsAreEqual(userRole, id))
{
return true;
}
}
}
}
return false;
}
function GetRequestObject()
{
if (window.XMLHttpRequest)
{
return new window.XMLHttpRequest;
}
else
{
try
{
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch (ex) {
return null;
}
}
}
function GuidsAreEqual(guid1, guid2) {
var isEqual = false;
if (guid1 == null || guid2 == null){
isEqual = false;
}
else {
isEqual = (guid1.replace(/[{}]/g, "").toLowerCase() == guid2.replace(/[{}]/g, "").toLowerCase());
}
return isEqual;
}
function salesmanagerrole() {
var field = Xrm.Page.ui.controls.get("fieldname");
var tabvisible = Xrm.Page.ui.tabs.get("tabname");
if (UserHasRole('Sales Manager')) {
tabvisible.setVisible("true");
field.setVisible("true");
}
}
Thursday, 22 November 2012
Code to Retrive the organization names in Dynamic CRM using c#
Right Click on the solutions --> Click Add service references
Right Click on the solutions --> Click Add service references
Then add the following references assemblies
- Microsoft.crm.sdk.proxy
- Microsoft.Xrm.Sdk
- System.ServiceModel
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Crm.Sdk;
namespace Organization
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ClientCredentials userCredentials = new ClientCredentials();
private void btnSrvValidate_Click(object sender, EventArgs e)
{
cmbOrg.Items.Clear();
List<string> orgNames = new List<string>();
userCredentials.UserName.UserName = txtUser.Text.Trim();
userCredentials.UserName.Password = txtPassword.Text.Trim();
string serverName=txtServer.Text.Trim();
string crmURI = "http://"+ serverName +"/XRMServices/2011/Discovery.svc";
DiscoveryServiceProxy discoveryProxy = new DiscoveryServiceProxy(new Uri(crmURI),null, userCredentials,null);
discoveryProxy.Authenticate();
try
{
RetrieveOrganizationsRequest retrieveOrganizationsRequest = new RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse retrieveOrganizationsResponse = discoveryProxy.Execute(retrieveOrganizationsRequest) as RetrieveOrganizationsResponse;
if (retrieveOrganizationsResponse.Details.Count != 0)
{
foreach (OrganizationDetail orgInfo in retrieveOrganizationsResponse.Details)
orgNames.Add(orgInfo.FriendlyName);
}
}
catch (Exception)
{
throw new Exception("Please check the Dynamics CRM Server URL");
}
cmbOrg.Items.AddRange(orgNames.ToArray());
cmbOrg.SelectedIndex = 0;
cmbOrg.Focus();
}
}
}
Result:
Get current view part of lotus notes using java
org.eclipse.ui.IWorkbenchWindow win = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow();
org.eclipse.ui.IWorkbenchPart part=win.getPartService().getActivePart();
String viewname=part.getTitle().toString().trim();
find the deleted contact from the lotus notes using java
Database db;
Document doc;
Document tempdoc;
Vector books = session.getAddressBooks();
Enumeration e = books.elements();
while (e.hasMoreElements())
{
db = (Database)e.nextElement();
db.open();
if(db.isOpen())
{
DocumentCollection dc = db.getAllDocuments();
doc = dc.getFirstDocument();
while (doc != null)
{
if (doc.isValid())
{
if (doc.isDeleted())
{
JOptionPane.showMessageDialog(doc.getItemValueString("Name") + "Contact is valid but deleted", JOptionPane.INFORMATION_MESSAGE);
}
else
return doc;
}
}
tempdoc = dc.getNextDocument();
doc.recycle();
doc = tempdoc;
}
dc.recycle();
}
Tuesday, 20 November 2012
Associate account with contact while creating a Additional contact from the Lead Form.
- Download XrmServiceToolkit. Extract the zip file.
- Then you have to add the following script to crm webresources:
- jquery.js
- json.js
- XrmServiceToolkit.js
- Save the following code as javascript file. Then add it to the webresources.
var requestMain = ""
xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:QualifyLeadRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>LeadId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>" + Xrm.Page.data.entity.getId() + "</a:Id>";
requestMain += " <a:LogicalName>lead</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>CreateAccount</c:key>";
requestMain += " <c:value i:type=\"d:boolean\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">true</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>CreateContact</c:key>";
requestMain += " <c:value i:type=\"d:boolean\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">true</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>CreateOpportunity</c:key>";
requestMain += " <c:value i:type=\"d:boolean\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">false</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>Status</c:key>";
requestMain += " <c:value i:type=\"a:OptionSetValue\">";
requestMain += " <a:Value>3</a:Value>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>OpportunityCurrencyId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>89c14850-a5f3-e011-8606-1cc1dee89aa8</a:Id>";
requestMain += " <a:LogicalName>transactioncurrency</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>OpportunityCustomerId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>e2d97648-a5f3-e011-8606-1cc1dee89aa8</a:Id>";
requestMain += " <a:LogicalName>account</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>SourceCampaignId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>0ada7648-a5f3-e011-8606-1cc1dee89aa8</a:Id>";
requestMain += " <a:LogicalName>campaign</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>QualifyLead</a:RequestName>";
requestMain += " </request>";
var resultXml = XrmServiceToolkit.Soap.Execute(requestMain);
var id = xmlToString(resultXml);// loadXML(resultXml);
return id;
}
function xmlToString(resultXml) {
if ($(resultXml).find('a\\:Id').length != 0) {
response = $(resultXml).find('a\\:Id').eq(0);
} else {
response = $(resultXml).find('Id').eq(0); ; //Chrome 24.0.1312.52 could not find node by the previous code
}
var result = ((typeof window.CrmEncodeDecode != 'undefined') ? window.CrmEncodeDecode.CrmXmlDecode(response.text()) : crmXmlDecode(response.text()));
return result;
}
function additionalContact(AccountId) {
var createContact = new XrmServiceToolkit.Soap.BusinessEntity("contact");
var salutation = Xrm.Page.data.entity.attributes.get("tvsi_ssalutation").getValue();
if(salutation != null)
{
createContact.attributes["tvsi_salutation"] = { value: salutation, type: "OptionSetValue" };
}
createContact.attributes["firstname"] = Xrm.Page.data.entity.attributes.get("tvsi_firstname").getValue();
createContact.attributes["lastname"] = Xrm.Page.data.entity.attributes.get("tvsi_lastname").getValue();
createContact.attributes["jobtitle"] = Xrm.Page.data.entity.attributes.get("tvsi_jobtitle").getValue();
createContact.attributes["emailaddress1"] = Xrm.Page.data.entity.attributes.get("tvsi_secondaryemail").getValue();
createContact.attributes["telephone1"] = Xrm.Page.data.entity.attributes.get("tvsi_secondbusinessphone").getValue();
createContact.attributes["mobilephone"] = Xrm.Page.data.entity.attributes.get("tvsi_mobilephone").getValue();
createContact.attributes["address1_line1"]=Xrm.Page.data.entity.attributes.get("address1_line1").getValue();
createContact.attributes["address1_line2"]=Xrm.Page.data.entity.attributes.get("address1_line2").getValue();
createContact.attributes["address1_line3"]=Xrm.Page.data.entity.attributes.get("address1_line3").getValue();
createContact.attributes["address1_city"]=Xrm.Page.data.entity.attributes.get("address1_city").getValue();
createContact.attributes["address1_postalcode"]=Xrm.Page.data.entity.attributes.get("address1_postalcode").getValue();
createContact.attributes["address1_stateorprovince"] = Xrm.Page.data.entity.attributes.get("address1_stateorprovince").getValue();
var country = Xrm.Page.data.entity.attributes.get("tvsi_countryregion").getValue();//.getSelectedOption().value;
if(country != null)
{
createContact.attributes["tvsi_countryregion0"]={ value: country, type: "OptionSetValue" };
}
createContact.attributes["parentcustomerid"] = { id: AccountId, logicalName: "account", type: "EntityReference" };
contactId1 = XrmServiceToolkit.Soap.Create(createContact);
}
function qualify() {
var id = qualifyLeadRequest();
if(Xrm.Page.data.entity.attributes.get("tvsi_lastname").getValue()!=null)
additionalContact(id);
alert("Successfully Converted to Account and Contact");
window.location.reload(true);
}
- Open VisualRibbonEditor Tool. Make a Connection with your CRM Server.
- Then Click Open. Entity Ribbon dialog will be Opened. There you have to select LEAD ribbon.
- Select ConverToLead button. After selected you need to click Action tab. Expand Javascript function.
- There you have to give a function name: qualify
- Library: /WebResources/new_filename
Qualify Lead automatically to Account, Contact and Opportunity using JavaScript
- Download XrmServiceToolkit. Extract the zip file.
- Then you have to add the following script to crm webresources:
- jquery.js
- json.js
- XrmServiceToolkit.js
Save the following code as javascript file. Then add it to the webresources.
var requestMain = ""
xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:QualifyLeadRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>LeadId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>" + Xrm.Page.data.entity.getId() + "</a:Id>";
requestMain += " <a:LogicalName>lead</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>CreateAccount</c:key>";
requestMain += " <c:value i:type=\"d:boolean\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">true</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>CreateContact</c:key>";
requestMain += " <c:value i:type=\"d:boolean\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">true</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>CreateOpportunity</c:key>";
requestMain += " <c:value i:type=\"d:boolean\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">true</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>Status</c:key>";
requestMain += " <c:value i:type=\"a:OptionSetValue\">";
requestMain += " <a:Value>3</a:Value>";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>OpportunityCurrencyId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>89c14850-a5f3-e011-8606-1cc1dee89aa8</a:Id>";
requestMain += " <a:LogicalName>transactioncurrency</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>OpportunityCustomerId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>e2d97648-a5f3-e011-8606-1cc1dee89aa8</a:Id>";
requestMain += " <a:LogicalName>account</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>SourceCampaignId</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">";
requestMain += " <a:Id>0ada7648-a5f3-e011-8606-1cc1dee89aa8</a:Id>";
requestMain += " <a:LogicalName>campaign</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += " </c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>QualifyLead</a:RequestName>";
requestMain += " </request>";
// requestMain += " </Execute>";
XrmServiceToolkit.Soap.Execute(requestMain);
}
function qualify() {
qualifyLeadRequest();
window.location.reload(true);
}
- Open VisualRibbonEditor Tool. Make a Connection with your CRM Server.
- Then Click Open. Entity Ribbon dialog will be Opened. There you have to select LEAD ribbon.
- Select ConverToLead button. After selected you need to click Action tab. Expand Javascript function.
- There you have to give a function name: qualify
- Library: /WebResources/new_filename
Subscribe to:
Posts (Atom)