Skip to main content

Posts

Showing posts from July, 2021

D365 get fetchxml alias value

 If we use an alias in our fetchxml query it will not retrieve the alias attribute like the default query. String inputstdssAttendeeFetchXML = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='std_stdssattendee' > <attribute name='std_attendeeroleid' /> <filter> <condition attribute='std_stdstdssid' operator='eq' value='{ inputstdss.GetAttributeValue<Guid>("std_stdstdssid")}' /> <condition attribute='statecode' operator='eq' value='0' /> <condition attribute='std_attendeeroleid' operator='not-null' />

D365 call another action from plugin

 If we want to call another plugin or action from plugin we can use this approach. // Call std Copy action into plugin OrganizationRequest request = new OrganizationRequest("std_Copystd"); request["Target"] = stdEntityReference; OrganizationResponse response = localContext.OrganizationService.Execute(request); string clonestdresultresult = (string)response.Results["Result"]; string ClonestdId = (string)response.Results["CloneId"];

D365 update entity without retrive entity into plugin

 we can update any entity record without retrieving  String stdattendeeFetchXML = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='std_stdattendee' > <attribute name='std_contactid' /> <attribute name='std_attendeecategory' /> <attribute name='std_attendeeroleid' /> <attribute name='std_name' /> <filter type='and' > <condition attribute='std_stdid' operator='eq' value='{ClonestdId}' /> <condition attribute='statecode' operator='eq' value='0' />

D365 grid selected row id into javascript

 If you want to get all selected values of a subgrid you can try with this sample. var gridContext = formContext.getControl("AttendeesSubgrid"); var allSelectedRows = gridContext.getGrid().getSelectedRows(); var attendeeList = []; allSelectedRows.forEach(GetSelectedRecord); function GetSelectedRecord(item) { var rowData = item._entityId; var attendiee = rowData.guid; attendeeList.push(attendiee); }

D365 plugin retrive entity data

  Retrieve Entity record data into plugin var inputcontract = (localContext.InputParameters["Target"] as Entity).ToEntity<student_contract>(); // retrive entity data Account accountEntity = localContext.OrganizationService.Retrieve( Account.EntityLogicalName, inputcontract.student_Account.Id, new ColumnSet(new String[] { "student_eventseriesid" })).ToEntity<Account>(); // You can also set the value without entity context ["student_eventseriesid"] = accountEntity.GetAttributeValue<EntityReference>("student_eventseriesid")

D365 java script on load event change code

 This is very common that some times we need to set value into another field based on change event or into form load event. Normally we define the code into load event and into change event. We can replace the load event using fireOnChange(); if (formContext.getAttribute("studentid")) { formContext.getAttribute("studentid").fireOnChange(); } If this field value has change event then you do not need to define into load event. fireOnChange() event will work for load event.

D365 lookup Custom filtering javascript

 In my case, I need to add custom filtering when I select a lookup it will populate another lookup. when the user will click on the search icon it will show only filter data.  I was following:  https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/addpresearch sample code: var demoLAB = demoLAB || {}; var classId; demoLAB.Stuedent = { Form: { Load: function (executionContext) { 'use strict'; var formContext = executionContext.getFormContext(); this.attachEvents(executionContext); }, attachEvents: function (executionContext) { 'use strict'; var formContext = executionContext.getFormContext(); var form = demoLAB.Stuedent.Form; // Student Change Event formContext.getAttribute("demo_studentId").addOnChange(form.studentOnChange); }, studentOnChange: function (executionContext) { &

D365 FetchXML query into plugin

 Generate the xml query using xrmtoolbox and try with this code sample. String eventsessionFetchXML = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='baseevt_eventsession' > <attribute name='baseevt_eventid' /> <attribute name='baseevt_sessionenddatetime' /> <attribute name='baseevt_sessionstartdatetime' /> <attribute name='baseevt_name' /> <attribute name='baseevt_description' /> <filter> <condition attribute='baseevt_eventid' operator='eq' value='{inputEntity.Id.ToString()}' /> </filter> </entity> </fetch>"; var eventSessionresult =

D365 Custom Action call from ribbon button javascript event

  If you want to call plugin from ribbon button click event with custom action, you can use this script. // Ribbon button click event call custom action executeCloneEvent: function (formContext, eventId) { var eventId = formContext.data.entity.getId(); var entityrecordId = eventId.substr(1, eventId.length - 2); var request = { entity: { entityType: "account", id: entityrecordId}, getMetadata: function () { return { boundParameter: "entity", parameterTypes: { "entity": { "typeName": "account", "structuralProperty": 5 }, }, operationType: 0, operationName: "acct_CloneEvent" }; } }; // Calling Plugin Xrm.WebApi.online.execute(request).then(function (result) {