ms crm 2015 Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/ms-crm-2015/ Microsoft Dynamics CRM . Microsoft Power Platform Wed, 25 Feb 2015 12:29:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/cropped-Microsoftdynamics365-blogs.png?fit=32%2C32 ms crm 2015 Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/ms-crm-2015/ 32 32 176351444 Activate / Deactivate a record using c# in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 ( using SetStateRequest ) http://microsoftdynamics.in/2015/02/25/activate-deactivate-a-record-using-c-in-ms-crm-2011-ms-crm-2013-ms-crm-2015-using-setstaterequest/ Wed, 25 Feb 2015 12:29:00 +0000 http://microsoftdynamics.in/2015/02/25/activate-deactivate-a-record-using-c-in-ms-crm-2011-ms-crm-2013-ms-crm-2015-using-setstaterequest/ hey , as we offensively get requirement to activate and reactivate a record then we start using update event , but there is a very simple method to do so , by using SetStateRequest : it require an assembly ” microsoft.crm.sdk.proxy.dll ” and using ” using Microsoft.Crm.Sdk.Messages;” . Code will be : SetStateRequest req = new SetStateRequest(); //the...

The post Activate / Deactivate a record using c# in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 ( using SetStateRequest ) appeared first on Microsoft Dynamics 365 Blog.

]]>

hey , as we offensively get requirement to activate and reactivate a record then we start using update event , but there is a very simple method to do so , by using SetStateRequest : it require an assembly ” microsoft.crm.sdk.proxy.dll ” and using ” using Microsoft.Crm.Sdk.Messages;” .
Code will be :
   SetStateRequest req = new SetStateRequest();
//the entity you want to change the state of
req.EntityMoniker = new EntityReference("new_abc", recordId);
//what should the new state be
req.State = new OptionSetValue(1);
//Pick an option from the status reason picklist to specify reason for state change
req.Status = new OptionSetValue(2);
SetStateResponse resp = (SetStateResponse)service.Execute(req);

SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Activate / Deactivate a record using c# in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 ( using SetStateRequest ) appeared first on Microsoft Dynamics 365 Blog.

]]>
2799
Fields that are not valid were specified for the entity – Importing Solution Error mscrm 2011 , mscrm 2013 , mscrm 2015 http://microsoftdynamics.in/2015/02/25/fields-that-are-not-valid-were-specified-for-the-entity-importing-solution-error-mscrm-2011-mscrm-2013-mscrm-2015/ Wed, 25 Feb 2015 12:12:00 +0000 http://microsoftdynamics.in/2015/02/25/fields-that-are-not-valid-were-specified-for-the-entity-importing-solution-error-mscrm-2011-mscrm-2013-mscrm-2015/ Hey , I was importing a solution today from an other Organization and got a Error new to me :  Fields that are not valid were specified for the entity , as there was no description i was little confused , but after few R&D came up with perfect resolution of the error . Reason ...

The post Fields that are not valid were specified for the entity – Importing Solution Error mscrm 2011 , mscrm 2013 , mscrm 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
Hey , I was importing a solution today from an other Organization and got a Error new to me :  Fields that are not valid were specified for the entity , as there was no description i was little confused , but after few R&D came up with perfect resolution of the error .

Reason 

  • Organization “A” conatined attribute ‘new_mscrm’ that was of type “single line” ,Later  We changed that the field  to be an currency Type.
  • But in Organization “B” was containg same field ‘new_mscrm’ of type “Single line”.
  • When we tried to import back the new solution to test environment we got this Import failure message as the solution we were importing was having a field ‘new_mscrm’ of type Currency

Solution

  • Just delete the field in the Organization in which you are importing the solution and reimport the same solution to it
Hope this helped you Thanks

SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Fields that are not valid were specified for the entity – Importing Solution Error mscrm 2011 , mscrm 2013 , mscrm 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
2800
Get field Name Using JavaScript in ms crm 2011 , ms crm 2013 , ms crm 2015 ( get dynamically field Label using JavaScript) http://microsoftdynamics.in/2015/02/19/get-field-name-using-javascript-in-ms-crm-2011-ms-crm-2013-ms-crm-2015-get-dynamically-field-label-using-javascript/ Thu, 19 Feb 2015 12:14:00 +0000 http://microsoftdynamics.in/2015/02/19/get-field-name-using-javascript-in-ms-crm-2011-ms-crm-2013-ms-crm-2015-get-dynamically-field-label-using-javascript/ Hi all below you will find how to get field label name using JavaScript . var fieldname = executionContext.getEventSource().getName(); NOTE: Remember to pass context as perimeter while submitting function Name. SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get field Name Using JavaScript in ms crm 2011 , ms crm 2013 , ms crm 2015 ( get dynamically field Label using JavaScript) appeared first on Microsoft Dynamics 365 Blog.

]]>

Hi all below you will find how to get field label name using JavaScript .
 var fieldname = executionContext.getEventSource().getName();
NOTE: Remember to pass context as perimeter while submitting function Name.


SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get field Name Using JavaScript in ms crm 2011 , ms crm 2013 , ms crm 2015 ( get dynamically field Label using JavaScript) appeared first on Microsoft Dynamics 365 Blog.

]]>
2803
Share A Record With Read Only Access Using Custom Workflow IN MS CRM 2011 , MS CRM 2013 , MS CRM 2015 http://microsoftdynamics.in/2015/01/05/share-a-record-with-read-only-access-using-custom-workflow-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/ Sun, 04 Jan 2015 20:00:00 +0000 http://microsoftdynamics.in/2015/01/05/share-a-record-with-read-only-access-using-custom-workflow-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/ Share a Record to a user without Assigning the record and with out giving Read access to that user , its a Custom Workflow to share a record with read only access , ( NOTE : You can not give read only access to owner of that record so , first we have to change...

The post Share A Record With Read Only Access Using Custom Workflow IN MS CRM 2011 , MS CRM 2013 , MS CRM 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
Share a Record to a user without Assigning the record and with out giving Read access to that user , its a Custom Workflow to share a record with read only access , ( NOTE : You can not give read only access to owner of that record so , first we have to change the owner and then we can share it to created by user with read only access )


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;
using Microsoft.Crm.Sdk.Messages;


namespace Readonlyaccess_sharerecord
{
    public class Class1 : CodeActivity
    {
        #region input parameter
        // In set property : give the user to whom record will be shared
        [ Input( “User_to_Share” )]
        // look up field of system user “Entity Name”
        [ ReferenceTarget (“systemuser” )]
        public InArgument <EntityReference > _User_to_Share { getset; }
        #endregion

        #region Output parameter
        //
        [ Output( “condition” )]
        public OutArgument <string > _condition { getset; }

        #endregion
        protected override void Execute( CodeActivityContext context)
        {

            IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext >();
            IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory >();
            IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
            #region paramters
            EntityReference User_to_Share = _User_to_Share.Get<EntityReference >(context);

            #endregion
            try
            {
                Entity Obj_entity = (Entity )service.Retrieve(workflowContext.PrimaryEntityName, workflowContext.PrimaryEntityId, newColumnSet (true ));

                try
                {
                    //no delete access
                    GrantAccessRequest grant = new GrantAccessRequest ();
                    grant.Target = new EntityReference (workflowContext.PrimaryEntityName, workflowContext.PrimaryEntityId);

                    PrincipalAccess principal = new PrincipalAccess ();
                    principal.Principal = User_to_Share;
                    principal.AccessMask = AccessRights .ReadAccess;
                    grant.PrincipalAccess = principal;
                    GrantAccessResponse grant_response = (GrantAccessResponse )service.Execute(grant);
                    _condition.Set(context, “1” );

                }
                catch ( Exception ex)
                {
                    _condition.Set(context, “0” );
                    throw new Exception( “Enable to Grant Read Access i.e.” + ex.Message);
                }

            }
            catch ( Exception ex)
            {
                throw new Exception( “Error Due To Master User Share i.e.” + ex.Message);
            }

        }
    }
}

1. Add Step to your Workflow.

2. Set Property and provide the user whom to share the record.

3. Forms become readonly after execution of record

SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Share A Record With Read Only Access Using Custom Workflow IN MS CRM 2011 , MS CRM 2013 , MS CRM 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
2805
Get Current Record Id of an entity using javascript in ms crm 2011 , ms crm 2013 and ms crm 2015 http://microsoftdynamics.in/2015/01/02/get-current-record-id-of-an-entity-using-javascript-in-ms-crm-2011-ms-crm-2013-and-ms-crm-2015/ Fri, 02 Jan 2015 10:56:00 +0000 http://microsoftdynamics.in/2015/01/02/get-current-record-id-of-an-entity-using-javascript-in-ms-crm-2011-ms-crm-2013-and-ms-crm-2015/ Get Record ID of an entity using javascript inn microsoft dynamics CRM . function Recordid() {     debugger;    var recordID = Xrm.Page.data.entity.getId();    var entityName = “new_entityname” ;    var urlcreation = “http://organizationame/main.aspx?etn=” +entityName+ “&pagetype=entityrecord&id=” + recordID + “#127104932” ; } SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get Current Record Id of an entity using javascript in ms crm 2011 , ms crm 2013 and ms crm 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
Get Record ID of an entity using javascript inn microsoft dynamics CRM .

function Recordid() {
    debugger;
   var recordID = Xrm.Page.data.entity.getId();
   var entityName = “new_entityname” ;
   var urlcreation = “http://organizationame/main.aspx?
etn=” +entityName+ “&pagetype=entityrecord&id=” + recordID + “#127104932” ;
}

SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get Current Record Id of an entity using javascript in ms crm 2011 , ms crm 2013 and ms crm 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
2806
Get Form Name of an Entity using JavaScript in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 http://microsoftdynamics.in/2015/01/02/get-form-name-of-an-entity-using-javascript-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/ http://microsoftdynamics.in/2015/01/02/get-form-name-of-an-entity-using-javascript-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/#comments Fri, 02 Jan 2015 10:45:00 +0000 http://microsoftdynamics.in/2015/01/02/get-form-name-of-an-entity-using-javascript-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/ Get Form name of an entity using javascript in microsoft dynamics crm ,This help in getting saved record form name from multipal forms ( if you want to show it in reports etc). function formname() {     debugger;     var name = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();     alert(name); } SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get Form Name of an Entity using JavaScript in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
Get Form name of an entity using javascript in microsoft dynamics crm ,This help in getting saved record form name from multipal forms ( if you want to show it in reports etc).

function formname() {
    debugger;
    var name = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

    alert(name);
}



SOURCE : JUST2CODE.IN Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get Form Name of an Entity using JavaScript in MS CRM 2011 , MS CRM 2013 , MS CRM 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
http://microsoftdynamics.in/2015/01/02/get-form-name-of-an-entity-using-javascript-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/feed/ 2 2807
Get all the Teams of User belong to using JavaScript (xml ) in ms crm 2011 , ms crm 2013 , ms crm 2015 http://microsoftdynamics.in/2014/12/30/get-all-the-teams-of-user-belong-to-using-javascript-xml-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/ Tue, 30 Dec 2014 09:36:00 +0000 http://microsoftdynamics.in/2014/12/30/get-all-the-teams-of-user-belong-to-using-javascript-xml-in-ms-crm-2011-ms-crm-2013-ms-crm-2015/ Get all the Teams User belongs to. 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>" + " <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>team</q1:EntityName>" + " <q1:ColumnSet xsi:type="q1:ColumnSet">" + " <q1:Attributes>" + " <q1:Attribute>name</q1:Attribute>" + " </q1:Attributes>" + " </q1:ColumnSet>" + "...

The post Get all the Teams of User belong to using JavaScript (xml ) in ms crm 2011 , ms crm 2013 , ms crm 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>

Get all the Teams User belongs to.


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>" +
" <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>team</q1:EntityName>" +
" <q1:ColumnSet xsi:type="q1:ColumnSet">" +
" <q1:Attributes>" +
" <q1:Attribute>name</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:LinkEntities>" +
" <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>teamid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>team</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>teammembership</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>teamid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkCriteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
" <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:LinkCriteria>" +
" </q1:LinkEntity>" +
" </q1:LinkEntities>" +
" </query>" +
" </RetrieveMultiple>" +
" </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/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);

// Save all entity nodes in an array.
var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");

var teamnames = new Array();
var teamids = new Array();

for (var i = 0; i < entityNodes.length; i++) {

var entityNode = entityNodes[i];
var teamidNode = entityNode.selectSingleNode("q1:teamid");
var teamNode = entityNode.selectSingleNode("q1:name");
var teamid = (teamidNode == null) ? null : teamidNode.text;
var team = (teamNode == null) ? null : teamNode.text;

teamnames[i] = team;
teamids[i] = teamid;
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get all the Teams of User belong to using JavaScript (xml ) in ms crm 2011 , ms crm 2013 , ms crm 2015 appeared first on Microsoft Dynamics 365 Blog.

]]>
2808
Get Schema Names of the field ( Attribute ) using JavaScript in ms crm http://microsoftdynamics.in/2014/12/30/get-schema-names-of-the-field-attribute-using-javascript-in-ms-crm/ Tue, 30 Dec 2014 09:32:00 +0000 http://microsoftdynamics.in/2014/12/30/get-schema-names-of-the-field-attribute-using-javascript-in-ms-crm/ To get the Schema Names of all the attributes or fields in given entity.  function getSchemaNamesList(entityName) { var request = "<Request xsi:type='RetrieveEntityRequest'>" + "<MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" + "<EntityItems>IncludeAttributes</EntityItems>" + "<LogicalName>" + entityName + "</LogicalName>" + "<IsCustomizable>1</IsCustomizable>" + "<RetrieveAsIfPublished>true</RetrieveAsIfPublished>" + "</Request>"; var result = queryMetadataService(request); var schemaNames = result.selectNodes("//EntityMetadata/Attributes/Attribute/SchemaName"); var namesList = ""; for (var i = 0;...

The post Get Schema Names of the field ( Attribute ) using JavaScript in ms crm appeared first on Microsoft Dynamics 365 Blog.

]]>

To get the Schema Names of all the attributes or fields in given entity. 


function getSchemaNamesList(entityName) {
var request = "<Request xsi:type='RetrieveEntityRequest'>" +
"<MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" +
"<EntityItems>IncludeAttributes</EntityItems>" +
"<LogicalName>" + entityName + "</LogicalName>" +
"<IsCustomizable>1</IsCustomizable>" +
"<RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
"</Request>";

var result = queryMetadataService(request);
var schemaNames = result.selectNodes("//EntityMetadata/Attributes/Attribute/SchemaName");
var namesList = "";
for (var i = 0; i < schemaNames.length; i++) {
namesList += schemaNames[i].text +",";
}
alert("Schema Names: "+namesList)
}

function queryMetadataService(request) {
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", '/mscrmservices/2007/MetadataService.asmx', false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');

var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<soap:Header>" +
"<CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + AUTHENTICATION_TYPE +
"</AuthenticationType>" +
"<OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + ORG_UNIQUE_NAME +
"</OrganizationName>" +
"<CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>00000000-0000-0000-0000-000000000000"+
"</CallerId>" +
"</CrmAuthenticationToken>" +
"</soap:Header>" +
"<soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + request +
"</Execute></soap:Body>" +
"</soap:Envelope>";

xmlhttp.send(soapMessage);
return xmlhttp.responseXML;
}


SOURCE : JUST2CODE.IN

Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get Schema Names of the field ( Attribute ) using JavaScript in ms crm appeared first on Microsoft Dynamics 365 Blog.

]]>
2810
New JavaScript function for ms crm 2011 , ms crm 2013 and ms crm 2015 , useful JavaScript method for Microsoft dynamics crm http://microsoftdynamics.in/2014/12/30/new-javascript-function-for-ms-crm-2011-ms-crm-2013-and-ms-crm-2015-useful-javascript-method-for-microsoft-dynamics-crm/ Tue, 30 Dec 2014 08:01:00 +0000 http://microsoftdynamics.in/2014/12/30/new-javascript-function-for-ms-crm-2011-ms-crm-2013-and-ms-crm-2015-useful-javascript-method-for-microsoft-dynamics-crm/         Below are the few useful properties, commands in ms crm 2011 ms crm 2013 and ms crm 2015 Javascript. You can work with them on form event say OnLoad. Click on the item below to go through the description about that. Get the string value of a Text field Set the string...

The post New JavaScript function for ms crm 2011 , ms crm 2013 and ms crm 2015 , useful JavaScript method for Microsoft dynamics crm appeared first on Microsoft Dynamics 365 Blog.

]]>

        Below are the few useful properties, commands in ms crm 2011 ms crm 2013 and ms crm 2015 Javascript. You can work with them on form event say OnLoad.

Click on the item below to go through the description about that.

  • Get the string value of a Text field
  • Set the string value of a Text field
  • Retrieve Optionset Value/Text
  • Get the label name of the field
  • Get Lookup field name(value)
  • Get Lookup field ID
  • Get current entity name
  • Get Type Code of lookup
  • Get reference entity name of lookup
  • Set Lookup field
  • Get Event generated field value
  • Get Organization Name
  • Get Organization Language Code
  • Get Server URL
  • Check for Dirty
  • Get GUID of current record
  • Whether the field is disabled or not
  • Get form type
  • Get required fields in the form
  • Save the current record
  • Save the current record
  • Set focus on the field
  • Hide a field on the form
  • Disable(Read only) and Enable a field
  • Close opened window
  • Open Browser Window
  • Get Logged-in User ID
  • Attach Event to control
  • Set Description field in E-mail entity
  • Set IFrame URL
  • Get Schema Names of the Attributes
  • Get Teams of User
  • Filtered Lookup
  • Trigger the Workflow
  • Set field value using query string parameter
  • Change the Status and Status Reason of the record
  • Get the current form name
  • Refresh the form
  • Hide left navigation item
  • Set field requirement level in run time
  • Get Organization URL

Get the string value of a Text field:

Returns the string value in the text field.
var fieldValue = Xrm.Page.data.entity.attributes.get("fieldName").getValue();

Set the string value of a Text field:

Set the string value for Text field.

Xrm.Page.data.entity.attributes.get("fieldName").setValue("New Value");

Retrieve Optionset Value/Text:

Returns the Value/Text of Optionset.

var optionSet = Xrm.Page.data.entity.attributes.get("optionSetName");
var optionSetText = optionSet.getText();
var optionSetValue = optionSet.getValue();

Get the label name of the field:

Get the Label of the specified field.

var fieldLabel = Xrm.Page.ui.controls.get("fieldName").getLabel();

Get the Lookup field value:

Get the value in given Lookup field.

var lookupValue=Xrm.Page.data.entity.attributes.get("lookupFieldName").getValue()[0].name;

Get the Lookup field ID:

Returns the ID of the record to which the lookup pointing to.

var lookupFieldId=Xrm.Page.data.entity.attributes.get("lookupFieldName").getValue()[0].id;

Get current entity name:

Returns the logical name of the current entity.

var entityName = Xrm.Page.data.entity.getEntityName();

Get Type Code of lookup:

Returns the code type with respect to an entity the lookup pointing to.

var objectTypeCode = Xrm.Page.getAttribute("lookupFieldName").getValue()[0].type;

Get reference entity name of lookup:

Returns the logical name of an entity the lookup pointing to.

var entityName = Xrm.Page.getAttribute("lookupField").getValue()[0].entityType;

Check for Dirty:

Returns a Boolean value indicating if any fields in the form have been modified.

var formChanged = Xrm.Page.data.entity.getIsDirty();

Set Lookup field:

Set the lookup field value.

var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = newId;
lookupValue[0].name = newName;
lookupValue[0].entityType = entityType;
Xrm.Page.getAttribute("lookupName").setValue(lookupValue);

Get event generated field value:

Returns the value of the field which generates the event.


function fieldValue_onchange(obj) {
var attribute = obj.getEventSource();
alert(attribute .getValue());
alert(Xrm.Page.ui.getCurrentControl().getAttribute().getValue());
}

Get Organization Name:

Returns the unique name of logged-in organization.

var orgName = Xrm.Page.context.getOrgUniqueName();

Get Organization Language Code:

Returns organization’s language code(LCID).
var orgLanguage = Xrm.Page.context.getUserLcid();

Get Server URL:

Returns the base server URL.

var orgName = Xrm.Page.context.getServerUrl();

Get GUID of current record:

Returns GUID for the record.

var guid = Xrm.Page.data.entity.getId();

Whether the field is disabled or not:

Returns a Boolean value indicating whether the control is disabled.

var fieldDisabled = Xrm.Page.ui.controls.get("fieldName").getDisabled();

Get form type:

Returns an integer value, indicates the form type: 1-Create, 2-Update

var FormType = Xrm.Page.ui.getFormType();

Get required fields in the form:

Returns required field names in the form:

Xrm.Page.data.entity.attributes.forEach( function (attribute, index) { 
if (attribute.getRequiredLevel() == "required" ) {
requiredFields += attribute.getName()+"n";
}
} );

Form Save:

Save the current form.

Xrm.Page.data.entity.save();

Form Save and Close:

Save and Close the form.

Xrm.Page.data.entity.save("saveandclose");

Set Focus:

Set focus on the control.
Xrm.Page.ui.controls.get("fieldName").setFocus();

Hide a field:

Hide the specified control.

Xrm.Page.ui.controls.get("fieldName").setVisible(false);

Disable and Enable a field:

Set field as Read only.

Xrm.Page.ui.controls.get("fieldName").setDisabled(true);

Set field as editable(Enable).

Xrm.Page.ui.controls.get("fieldName").setDisabled(false);

Close window:

Close the current opened window.

Xrm.Page.ui.close();

Open New window:

Open a new browser window with specified URL.

window.open("http://google.com", 
'name',
'width=900,height=800,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,modal=yes');

Get Logged-in User ID:

Get the Logged-in User ID.

var userID = Xrm.Page.context.getUserId();

Attach Event to Control:

As CRM 2011 does not supports some events like onclick and ondblclick, we can attach a particular event to the control on form load.

function onload_method() {
var control = document.getElementById("fieldName");
if (control) {
control.attachEvent("onclick", control_clicked);
control.attachEvent("oncdbllick", control_dblclicked);
}
}

function control_clicked(){
//This function fires on field click
//onclick logic goes here
}

function control_dblclicked(){
//This function fires on field double click
//ondblclick logic goes here
}

Set Description field in E-mail entity:

The Description field in E-mail entity is inside an IFrame and since its made for text decoration, text inside this field is enclosed with html tags. So, we can’t directly set the field value. Below is the solution to set this field OnLoad of the form.


function onload_method() {
var descriptionFrame = document.getElementById('descriptionIFrame');
descriptionFrame.attachEvent('onreadystatechange', setValue);
}

function setValue () {
var descriptionFrame = document.getElementById('descriptionIFrame');
if (descriptionFrame.readyState != 'complete')
return;
var htmlTag = "<:html> Value for Description field...<:/html>";
var descriptionWindow = document.frames['descriptionIFrame'];
descriptionWindow.document.body.innerHTML = htmlTag;
}

Set IFrame URL:

To change the URL of IFrame and can also pass values in query string.


function setIFrameURL() {
var IFrame = Xrm.Page.ui.controls.get("IFRAME_GoogleMap");
var countryName = Xrm.Page.data.entity.attributes.get("address1_country").getValue();
var newTarget= "http://maps.google.com/maps?q="+countryName;
IFrame.setSrc(newTarget);
}

Get Schema Names of the Attributes:

To get the Schema Names of all the attributes in given entity.


function getSchemaNamesList(entityName) {
var request = "<Request xsi:type='RetrieveEntityRequest'>" +
"<MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" +
"<EntityItems>IncludeAttributes</EntityItems>" +
"<LogicalName>" + entityName + "</LogicalName>" +
"<IsCustomizable>1</IsCustomizable>" +
"<RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
"</Request>";

var result = queryMetadataService(request);
var schemaNames = result.selectNodes("//EntityMetadata/Attributes/Attribute/SchemaName");
var namesList = "";
for (var i = 0; i < schemaNames.length; i++) {
namesList += schemaNames[i].text +",";
}
alert("Schema Names: "+namesList)
}

function queryMetadataService(request) {
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", '/mscrmservices/2007/MetadataService.asmx', false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');

var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<soap:Header>" +
"<CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + AUTHENTICATION_TYPE +
"</AuthenticationType>" +
"<OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + ORG_UNIQUE_NAME +
"</OrganizationName>" +
"<CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>00000000-0000-0000-0000-000000000000"+
"</CallerId>" +
"</CrmAuthenticationToken>" +
"</soap:Header>" +
"<soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + request +
"</Execute></soap:Body>" +
"</soap:Envelope>";

xmlhttp.send(soapMessage);
return xmlhttp.responseXML;
}

Get Teams of User:

Get all the Teams User belongs to.

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>" +
" <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>team</q1:EntityName>" +
" <q1:ColumnSet xsi:type="q1:ColumnSet">" +
" <q1:Attributes>" +
" <q1:Attribute>name</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:LinkEntities>" +
" <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>teamid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>team</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>teammembership</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>teamid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkCriteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
" <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:LinkCriteria>" +
" </q1:LinkEntity>" +
" </q1:LinkEntities>" +
" </query>" +
" </RetrieveMultiple>" +
" </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/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);

// Save all entity nodes in an array.
var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");

var teamnames = new Array();
var teamids = new Array();

for (var i = 0; i < entityNodes.length; i++) {

var entityNode = entityNodes[i];
var teamidNode = entityNode.selectSingleNode("q1:teamid");
var teamNode = entityNode.selectSingleNode("q1:name");
var teamid = (teamidNode == null) ? null : teamidNode.text;
var team = (teamNode == null) ? null : teamNode.text;

teamnames[i] = team;
teamids[i] = teamid;
}

Filtered Lookup:

Filter the lookup view based the value selected in another lookup.

You can get fetchXml value from your CRM system by following the steps below.
Open Dynamics CRM
à Click Advanced Find on ribbon à Select Target(say) in “Look for:” list à Select Owning Team(Team) in list below à Select Team under Owning Team(Team) à Leave Equals as default filter à In Enter Value lookup select one record à Click Download Fetch XML on ribbon. You will get fetch XML string and put that code in variable ‘fetchXml’ in below code and replace GUID from ‘value’ property in <condition> tag with dynamic variable, here it is _teamId.


function changeCustomView() {
//new_targetvalue is a lookup to new_target entity which we are filtering present on new_test entity form
//new_team is a lookup to Team on new_test entity form by which new_targetvalue lookup filtering
//new_targetid is a primary key attribute in new_target entity
//teamid is a lookup to Team on new_target entity form

var entityName = "new_target"; //Filtering lookup entity name
var _team = Xrm.Page.data.entity.attributes.get("new_team"); //Team on which filtering depends on
var viewDisplayName = "CustomTargetFilteredView";

// If new_team contains a value, then filter the new_targetvalue lookup based on new_team selected
if (_team.getValue() != null) {
var _teamId = _team.getValue()[0].id;
var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; // Unique viewID
var fetchXml = "<?xml version='1.0'?>" +
"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>" +
"<entity name='new_target'> <attribute name='new_targetid'/>" +
"<attribute name='new_name'/>" +
"<attribute name='createdon'/>" +
"<order descending='false' attribute='new_name'/>" +
"<link-entity name='team' alias='aa' to='owningteam' from='teamid'>" +
"<filter type='and'>"+
"<condition attribute='teamid' value='" + _teamId + "' uitype='team' operator='eq'/>" +
"</filter> " +
"</link-entity> " +
"</entity> " +
"</fetch>";

var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='new_name' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='new_targetid'>" +
"<cell name='new_name'/>" +
"width='100' />" +
"</row>" +
"</grid>";

var lookup = Xrm.Page.ui.controls.get("new_targetvalue");
lookup.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
lookup.setDefaultView(viewId);
document.getElementById("new_targetvalue").setAttribute("disableViewPicker", "1");
}
}

Trigger the Workflow:

Trigger the workflow(process) using javascript.

Steps to be followed to implement javascript to trigger workflow:
à Download JQuery here.
à Crate one JScript webresource and upload this downloaded JQuery.
à Create one JScript webresource for the below code and register to the CRM form where you want to run this script.


function TriggerWorkflow() {

// Get the Workflow ID
var workflowId = GetProcessId();
if (workflowId[0].results.length > 0) {
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>" +
"<Execute xmlns="http://schemas.microsoft.com/crm/2007/WebServices">" +
"<Request xsi:type="ExecuteWorkflowRequest">" +
"<EntityId>" + Xrm.Page.data.entity.getId() + "</EntityId>" +
"<WorkflowId>" + workflowId[0].results[0].WorkflowId + "</WorkflowId>" +
"</Request>" +
"</Execute>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", true);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
}
}

function GetProcessId() {
// Pass the workflow name manually to get the Id of the workflow
var processName = "My Workflow Name";

// Get the server URL
var serverUrl = Xrm.Page.context.getServerUrl();
var oDataUri = serverUrl + "/xrmservices/2011/OrganizationData.svc/WorkflowSet?$select=WorkflowId&$filter=Name eq '" + processName + "' and ActiveWorkflowId/Id ne null";
var jSonArray = new Array();

jQuery.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataUri,
async: false,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (data && data.d != null) {
jSonArray.push(data.d);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert("Error : has occured during retrieval of the workflowId");
}
});
return jSonArray;
}

Set field value using query string parameter:

When we click on some ribbon button or on some event, the new Account window will open with setting the Account Name field by passing that value in query string parameter.


function openAccountWindow(value) {
var windowProperties = 'width=900,height=800,toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,modal=yes';
var encodedParam = encodeURIComponent("name = New Test Account");
window.open("http://serverName/OrgName/main.aspx?etc=1&extraqs="+ encodedParam +"&pagetype=entityrecord",
'accountWindow',
windowProperties);
}

Change the Status and Status Reason of the record:

We can not change the Status and Status Reason of the record directly or by REST call. We can do so using SOAP request. And Status and Status Reason should be matched to perform this action.

function SetState(entityName, entityId, statusReason, state) {
var serverURL = Xrm.Page.context.getServerUrl();
var setStateRequest = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
'<s:Body>' +
'<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
'<request i:type="a:UpdateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">' +
'<a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">' +
'<a:KeyValuePairOfstringanyType>' +
'<b:key>EntityMoniker</b:key>' +
'<b:value i:type="a:EntityReference">' +
'<a:Id>' + entityId + '</a:Id>' +
'<a:LogicalName>' + entityName + '</a:LogicalName>' +
'<a:Name i:nil="true"></a:Name>' +
'</b:value>' +
'</a:KeyValuePairOfstringanyType>' +
'<a:KeyValuePairOfstringanyType>' +
'<b:key>State</b:key>' +
'<b:value i:type="a:OptionSetValue">' +
'<a:Value>' + state + '</a:Value>' +
'</b:value>' +
'</a:KeyValuePairOfstringanyType>' +
'<a:KeyValuePairOfstringanyType>' +
'<b:key>Status</b:key>' +
'<b:value i:type="a:OptionSetValue">' +
'<a:Value>' + statusReason + '</a:Value>' +
'</b:value>' +
'</a:KeyValuePairOfstringanyType>' +
'</a:Parameters>' +
'<a:RequestId i:nil="true"></a:RequestId>' +
'<a:RequestName>SetState</a:RequestName>' +
'</request>' +
'</Execute>' +
'</s:Body>' +
'</s:Envelope>';

var req = new XMLHttpRequest();
req.open("POST", getServerUrlForSetState(), false);

req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");

req.send(setStateRequest);

if (req.status != 200) {
getError(req.responseXML);
}
}

Get the current form name:

Returns the name of the selected form in the record.

Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

Refresh the form:

Refresh the current form.

window.parent.location.reload();

Hide left navigation item:

Hide the left navigation item based on some condition.

var items = Xrm.Page.ui.navigation.items.get();

for (var i in items) {
var item = items[i];

if (item.getLabel() == "Accounts") {
item.setVisible(false);
}
}

Set field requirement level in run time:

Set the field requirement level to either Required or Recommended or NoConstraint in run time.

// No Constraint 
Xrm.Page.getAttribute("field_name").setRequiredLevel("none");

// Business Required
Xrm.Page.getAttribute("field_name").setRequiredLevel("required");

// Business Recommended
Xrm.Page.getAttribute("field_name").setRequiredLevel("recommended");

Get the CRM Organization URL:

Retrieve the CRM Organization URL with respect to the current domain name.
For example, if you are browsing the CRM instance with IP, then the return value would be like this: http(s)://<IP>/<OrgName>
If you are browsing with domain name, it would be like this: http(s)://<DomainName>/<OrgName>

function GetServerUrlRegExp(location) {
var urlReg = new RegExp(/http[s]?://[0-9.:]+/[^/]+/);
var ServerUrl = Xrm.Page.context.getServerUrl();
if (window.location.href.match(urlReg) != null) {
ServerUrl = window.location.href.match(urlReg).toString();
}
if (ServerUrl.match(//$/)) {
ServerUrl = ServerUrl.substring(0, ServerUrl.length - 1);
}
return ServerUrl;
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post New JavaScript function for ms crm 2011 , ms crm 2013 and ms crm 2015 , useful JavaScript method for Microsoft dynamics crm appeared first on Microsoft Dynamics 365 Blog.

]]>
2811
Microsoft dynamics CRM 2015 trail key ( 90 days trial key ) Download ( MS CRM 2015 90 days Download ) http://microsoftdynamics.in/2014/12/23/microsoft-dynamics-crm-2015-trail-key-90-days-trial-key-download-ms-crm-2015-90-days-download/ Tue, 23 Dec 2014 05:41:00 +0000 http://microsoftdynamics.in/2014/12/23/microsoft-dynamics-crm-2015-trail-key-90-days-trial-key-download-ms-crm-2015-90-days-download/ Hello guys , Below is the link to official Site to download MS CRM 2015 and 90 Days Trial Key . Microsoft Dynamics CRM Workgroup Server 2015 (5 CAL limit): XY8GN-DF2MC-FV482-YM9YP-HH6H2 Microsoft Dynamics CRM Server 2015 (no CAL limit): C6BDP-T6NK9-8TXJP-36WTB-TXW7V Download Link : http://www.microsoft.com/en-us/download/details.aspx?id=45012 FOR MS CRM 2013 DOWNLOAD : Click here SOURCE : JUST2CODE.IN Subscribe...

The post Microsoft dynamics CRM 2015 trail key ( 90 days trial key ) Download ( MS CRM 2015 90 days Download ) appeared first on Microsoft Dynamics 365 Blog.

]]>
Hello guys , Below is the link to official Site to download MS CRM 2015 and 90 Days Trial Key .

    • Microsoft Dynamics CRM Workgroup Server 2015 (5 CAL limit): XY8GN-DF2MC-FV482-YM9YP-HH6H2
    • Microsoft Dynamics CRM Server 2015 (no CAL limit): C6BDP-T6NK9-8TXJP-36WTB-TXW7V


FOR MS CRM 2013 DOWNLOAD : Click here


SOURCE : JUST2CODE.IN

Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Microsoft dynamics CRM 2015 trail key ( 90 days trial key ) Download ( MS CRM 2015 90 days Download ) appeared first on Microsoft Dynamics 365 Blog.

]]>
2814