My Photo

Microsoft Dynamics 365

Official Blog for Microsoft Dynamics Functional and Technical Solutions....
Browsing Category " mscrm "

Update and delete entities using the Web API Dynamics 365 V9

Follow link to "Retrieve multiple entity record using Web API " above step is required to understand the how to connect with Dynamics 365 using Web API.

for update we can use SendAsync

----------------------------------------------------------------------------------

JObject content= new JObject();
                    content.Add("statuscode", "100000000");
                    content.Add("statecode", "0");

                    content.Add("new_name","name");

 HttpRequestMessage updateRequest2 = new HttpRequestMessage(new HttpMethod("PATCH"),  "[Organization URL]api/data/v9.0/new_test(00000000-0000-0000-0000-000000000001)?$select=new_testid,statuscode,statecode,sab_name"  );
                        updateRequest2.Content = new StringContent(Content.ToString(),Encoding.UTF8, "application/json");
                        HttpResponseMessage updateResponse1 = httpClient.SendAsync(updateRequest2).Result;
                        if (updateResponse1.IsSuccessStatusCode)
                        {
                            //Get the response content  and parse it.
                           JObject body = new JObject();
                            body.Add("success", "true");
                            return body;
                        }
                        else
                        {
                            throw new Exception("error");

                        }

--------------------------------------------------------------------------------------

Hope this helped. thanks

SOURCE : mscrm.com

Parse JSON in C# (without Newton JSON) specially for Dynamics 365 CRM V9

Below is the Json from which i need to get  "Name", "Email ID" and "Phone number" , Please use https://jsonformatter.curiousconcept.com/ for JSON Formatter.


{'context':{
'agent':{'name':'manish'},
'customer':{'browserType':'Chrome','os':'WINDOWS'},
'chat':{'prechatSurvey':[{'question':'What is your name?','answer':'manish'},{'question':'Phone Number','answer':'9393939384'},{'question':'Email Address','answer':'manish@gmail.com'}]}}
}
1. Context is root list object

public class RootObject
    {
        public Context context { get; set; }
    }
2. As you can see under Context there are 3 more list 'agent , 'customer' and 'chat'

  public class Context
    {
        public Agent agent { get; set; }
        public Customer customer { get; set; }
        public Chat chat { get; set; }
    }
3. Now Chat has list object,
  public class Agent
    {
        public string name { get; set; }
    }
    public class Customer
    {
        public string browserType { get; set; }    
        public string os { get; set; }
    }

4. Now 'Chat' has a list 'prechatSurvey'

public class Chat
    {
        public List<PrechatSurvey> prechatSurvey { get; set; }
    }
5. 'prechatSurvey' contain Question and answer required
public class PrechatSurvey
    {
        public string question { get; set; }
        public string answer { get; set; }
    }
Now we can parse the JSON and get required value, please refer below code
 -----------------------------------------------------------------------------------------------
   class Program
    {
        static void Main(string[] args)
        {
            var parameterValue1 = "{'context':{'agent':{'name':'manish'},'customer':{'browserType':'Chrome','os':'WINDOWS'},'chat':{'prechatSurvey':[{'question':'What is your name?','answer':'manish'},{'question':'Phone Number','answer':'9211151304'},{'question':'Email Address','answer':'manishch@gmail.com'}]}}}";
            string fullname = string.Empty;
            string Phonenumber = string.Empty;
            string emailID = string.Empty;
            string message = string.Empty;
            byte[] result = Encoding.UTF8.GetBytes(parameterValue1.Replace("'", "\""));
            using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(result, XmlDictionaryReaderQuotas.Max))
            {
                var outputSerialiser = new DataContractJsonSerializer(typeof(RootObject));
                RootObject output = (RootObject)outputSerialiser.ReadObject(jsonReader);
                List<PrechatSurvey> prechatSurveyList = output.context.chat.prechatSurvey;
                foreach (PrechatSurvey prechatSurvey in prechatSurveyList)
                {
                    string question = prechatSurvey.question;
                    switch (question)
                    {
                        case "What is your name?":
                            fullname = prechatSurvey.answer;
                            break;
                        case "Phone Number":
                            Phonenumber = prechatSurvey.answer;
                            break;
                        case "Email Address":
                            emailID = prechatSurvey.answer;
                            break;                      
                        default:
                            break;
                    }
                }
            }
           
        }
    }
    public class Agent
    {
        public string name { get; set; }
    }
    public class Customer
    {
      
        public string browserType { get; set; }    
        public string os { get; set; }
    }
    public class PrechatSurvey
    {
        public string question { get; set; }
        public string answer { get; set; }
    }
    public class Chat
    {
        public List<PrechatSurvey> prechatSurvey { get; set; }
    }
    public class Context
    {
        public Agent agent { get; set; }
        public Customer customer { get; set; }
        public Chat chat { get; set; }
    }
    public class RootObject
    {
        public Context context { get; set; }
    }
}
----------------------------------------------------------------------------------------
Hope this was Helpfull .thanks
SOURCE : mscrm.com

Method Xrm.Page.ui.formSelector does not work in tablet and mobile device. Use getClient() in Dynamics 365 , MS CRM


Below are some of the examples that will not work in tablets when using MSCRM


Xrm.Page.context. getCurrentThemeXrm.Page.ui ViewPort Methods
Xrm.Page.data.entity. getDataXmlXrm.Page.ui control Web resource and IFRAME control methods
Xrm.Page.ui. formSelector object methodsXrm.Page.ui tab. setDisplayState
Xrm.Page.ui. navigation.items collectionXrm.Utility. openWebResource
Xrm.Page.ui. refreshRibbon

When these method are executed in Tablet or mobile device then these will return nothing and defining will return undefined.
So  if we are customization it for tablet we should distinguish the client device in JS and write code .

var isCrmForTablets = (Xrm.Page.context.client.getClient() == “Mobile”)
if (isCrmForTablets)
{
// Code for CRM for tablets only goes here,
}
else
{
// Code for web browser or CRM for Outlook only goes here.
}
// Code for any client goes here.
 
To make sure which commands will work in tablet then include a command rule for more info refer Here.

Hope it will help. thanks

SOURCE : mscrm.com

ERROR 401 Unauthorized Access is Denied in mscrm Claims Based Authentication

Last Sunday my client was unable to login to the CRM and was showing below error :

HTTP Error 401 - Unauthorized Access is denied.

I checked and found this error is of claims based authentication or IFD. 

It was working fine from past 90 days but i just followed the below Microsoft article and error was resolved.

Cause mentioned  :  
The Token-signing certificate and Token-Decrypting certificate in ADFS will automatically be renewed by the Auto Certificate Rollover feature because these certificates reach their expiration date.

Microsoft KB Article : Click Here 

Set only contact entity or only Account entity customer field lookup in case / Opportunity for ms crm

Set potential customer look up field to only for contact entity record.

By default out of the box functionality gave a pop up with two entity type -contact & account for customer lookup field ,
if your requirement is to set only contact or only account as entity it can be done using javascript as given below ,

Both Contact and Account are viewed by Default 

ERROR : The specified user is either disabled or is not a member of any business unit in Microsoft Dynamics CRM while activating workflow or saving a record ( The System Could not log you on. This could be because your user record or the business unit you belong to has been disabled in microsoft Dynamics CRM )

While activating one draft workflow,  i was getting an error .

The System Could not log you on. This could be because your user record or the business unit you belong to has been disabled in Microsoft Dynamics CRM 

Set Field Read Only Using JavaScript In MSCRM ( Lock Field in MS CRM )



Hey Below is the Code To Set a Attribute / field on form Read only (Lock) using JavaScript in MS CRM .


// Get Control of entity
Xrm.Page.ui.controls.get("new_companyreference");
// Now set the property to lock the field
ToBeReadOnlyControl.setDisabled(true);


Note : Xrm.Page.ui.controls.get("new_companyreference"); by this we get full UI controls of the attribute / field by which we can set or get any ui property of that field .


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