Tuesday, 9 March 2021

Show Notification on Home Page Grid Dynamic 365

  var notification =

    {

    type: 2,

    level: 4, // information. 1. success, 2. error, 3. warning

    message: "Doc is being generating for the selected records."

    };

    Xrm.App.addGlobalNotification(notification)

Monday, 28 September 2020

Monday, 13 January 2020

Call Azure function from Javascript

 <script type="text/javascript">
        function CallAzurefunction() {
            debugger;
            var data = {
                'name': 'testazure function'
            };

            var req = new XMLHttpRequest();
            req.open("POST", "AzureFunctionUrl&name=test", true);
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("crossDomain", true);
            req.onreadystatechange = function () {
                if (req.readyState == 4 /* complete */) {
                    req.onreadystatechange = null;
                    if (req.status == 200) {

                        // alert("Project created");
                    } else {

                        //alert(error.message);
                    }
                }
            };
            //req.send(JSON.stringify(data));

            req.send();

        }
    </script>

Call Azure function from C# code






 string azureFunctionUrl = "";
            var content = new StringContent(jsonObjectString, Encoding.UTF8, "application/json");
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("x-functions-key", "y3cQDQDJaPuZ6BH8G2aS4XoKo1c0ik0KjirVwU4REHvSBcFqWVTQrg==");
                client.DefaultRequestHeaders.Add("Accept", "application/json");
                //client.DefaultRequestHeaders.Add("Content-Type", "application/json; charset=utf-8");
                using (HttpResponseMessage response = client.PostAsync(azureFunctionUrl, content).Result)
                using (HttpContent respContent = response.Content)
                {
                    // ... Read the response as a string.
                    var tr = respContent.ReadAsStringAsync().Result;
                    // ... deserialize the response, we know it has a 'result' field
                    //dynamic azureResponse = JsonConvert.DeserializeObject(tr);
                    //// ... read the data we want
                    //result = azureResponse.result;
                }
            }

Fetch Xml,Group by Date field and then sort by same Date field


Get Latest records by ab_effectivedate field and aggregate EarnCode decimal field.

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'> <entity name='ab_deductionfringes'>
<attribute name='ab_effectivedate' alias='EffectiveDateYear' groupby='true' dategrouping='year'/>
<attribute name='ab_effectivedate' alias='EffectiveDateMonth' groupby='true'dategrouping='month'/>
<attribute name='ab_effectivedate' alias='EffectiveDateDay' groupby='true' dategrouping='day'/>
<attribute name='ab_earncode' alias='EarnCode' aggregate='sum' />
<order alias='EffectiveDateYear' descending='true' />
<order alias='EffectiveDateMonth' descending='true' />
<order alias='EffectiveDateDay' descending='true' />
 <filter type='and'>
  <condition attribute='ab_union' operator='eq'  uitype='ab_union' value='" + unionId + @"' />
   <condition attribute='ab_trade' operator='eq'  uitype='ab_trade' value='" + tradeId + @"' />
   <condition attribute='statecode' operator='eq' value='0' />
   <condition attribute='ab_effectivedate' operator='not-null' />
 </filter>
 </entity>
</fetch>

Thursday, 14 November 2019

Dynamic 365, Create Associated view or other OOB view in C#

Sometimes the OOB view deleted mistakenly and it create problems.
The same scenario come with me, I have custom entity Bid and its associated view deleted mistakenly and we need to create one to many relationship with same Bid entity.
But the associated view of custom entity bid is deleted so we can't create relationship.

Through following code i created the associated view of Bid entity and then i create one to many relationship with same bid entity.

                // Create the view.
                System.String layoutXml =@"<grid name='resultset' object='3' jump='ab_name' select='1'
                                            preview='1' icon='1'>
                                            <row name='result' id='ab_bidid'>
                                            <cell name='ab_name' width='150' />
                                            </row>
                                        </grid>";

 System.String fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                <entity name='ab_bid'>
                  <attribute name='ab_name' />
                  <attribute name='ab_bidid' />
                  <filter type='and'>
                    <condition attribute='statecode' operator='eq' value='0' />
                  </filter>
                  <order attribute='ab_name' descending='false' />
                </entity>
              </fetch>";
 
                
 
                Entity entity = new Entity("savedquery");
                entity["description"] = "Bid Associated View";
                entity["name"] = "Bid Associated View";
                entity["querytype"] = 2; // 2 is type code of Associated view
                entity["returnedtypecode"] = "ab_bid";  // enity name
                entity["fetchxml"] = fetchXml;
 
                entity["layoutxml"] = layoutXml;
               
                Guid _customViewId = service.Create(entity);

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...