Skip to main content

Posts

Showing posts from 2021

Add additional text into D365 portal label

 If we want to add additional label value to the D365 portal we can use this approach $(document).ready(function (){ var currentLabel = $("label#std_data_storage_confirmation_label").html(); var labelWithDatenSchutzLink = currentLabel + " <a href='https://www.fedalic.de/' class='fedalic-blue' target='_blank' >Datenschutz</a>"; $("label#std_data_storage_confirmation_label").html(labelWithDatenSchutzLink); }); 65 

Rich Text Field are showing in plain text with html tags in Dynamics 365 Portals

 In my D365 form, I have some fields that contains HTML tags. like link. When I show this form into the portal I can see the tag. which is not expecting.  i use the following javascript $(document).ready(function(){ // Set the value into tem variable var std_footer_presave = $('#std_footer').val(); //Remove HTML tag $("#std_footer").parent().append("<span class='text'>" + $("#std_footer").val()+ "</span>"); $("#std_footer").remove(); // Form validation for next button or save button window.webFormClientValidate = function () { // Create hidden field $('#std_footer').val(''); $('#std_footer').hide(); $('<input>', { type: 'hidden', id: 'std_footer', name: 'std_footer', value: '' }).appendTo('form'); // Set value into hidden field $('

d365 portal How can I redirect to login page if not logged in

 Go to your form select Authentication Required Yes. In my case, I was using the Advance form.

d365 portal set browser tab title

 d365 portal browser tab title is the combination of 2 titles.  If you want to set the title portal for  every page like: Student Portal Class Portal  then you need to set the value into Browser Title Suffix If you do not want to use this text just remove it. For each page, title Go to your web page-> localized content->select the content page->change the title.

d365 portal form field set as hidden field.

 If you want to use the form field as a hidden field into the form you can use this. $(document).ready(function(){ $('#std_name').val(''); $('#std_name_label').hide(); $('#std_name').hide(); $('<input>', { type: 'hidden', id: 'std_name', name: 'std_name', value: '' }).appendTo('form'); }); At any event, you can set the value that will behave life form field. 

D365 portal get date field value into java script

 If you want to date field value into custom java script. You can use this script. $(document).ready(function(){ var CurrentDate = new Date(); var stdregistrationclosedatetime = $("#stdregistrationclosedatetime").datepicker({ dateFormat: 'dd,MM,yyyy' }).val(); var registrationclosedatetime = new Date(stdregistrationclosedatetime) if(CurrentDate>registrationclosedatetime){ $("#UpdateButton").hide(); } });

D365 portal Custom Javascript is not working into Profile web page

I am trying to add custom JavaScript into Profile web page but it is not working. I also try to switch content page but that is also not working, it shows disable. Solution: Click related and web page. select web page and add your script.

D365 portal Error: Incorrect contents fetched, please reload

 The error is coming from your custom java script when you click submit button. I my case i was using webFormClientValidate but forgot to return true because it always expect return true if not false. window.webFormClientValidate = function () { // your validation logic return true; }; For your case please check your custom java script code and find out that you miss anything to return or not.

D365 portal currency field formatting

D365 portal is not able to format the currency field. It shows like that I also try to use mask but that is not solve my problem. https://oliverrodrigues365.com/2020/04/15/power-apps-portals-adding-field-mask/ I use the following java script. $(document).ready(function(){ // Hide default currency icon from this form $("span."+"input-group-addon").hide(); // Set currency icon var std_classfee_onload = parseFloat($('#std_classfee').val()); $('#std_classfee').val(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(parseFloat(std_classfee_onload))); // Form validation for next button or save button click window.webFormClientValidate = function () { // Presave remove currency icon var std_classfee_presave = parseFloat($('#std_classfee').val()); $('#std_classfee').val(std_classfee_presave);

D365 portal date field formatting

 In portal the CRM form date field is not showing in to the right format. it shows like this. If you want to format this date field you can use this script. function setDateTimeFieldValue(fieldId, dateValue) { //Get the submit field var $submitField = $("#" + fieldId); //Get the display field var $displayField = $submitField.nextAll(".datetimepicker").children("input"); //Get the display date format var dateFormat = $displayField.attr("data-date-format"); //Set the submit field. Remember this needs to be in UTC and the format must be exact. $submitField.val(moment.utc(dateValue).format("YYYY-MM-DDTHH:mm:ss.SSSSSSS")); //Set the display field using the page's date format $displayField.val(moment(dateValue).format(dateFormat)); } Call this function with field name and value var std__eventstartdatetime = setDateTimeFieldValue('std__eventstartdatetime',data.value[0].s

D365 portal hide Azure AD login button

 Open theme.css of your portal. add this line at the end of the file. .btn-line { visibility: hidden; } Go to your portal management and into site settings set Authentication/Registration/ExternalLoginEnabled False. Now your portal login window will look like this.

D365 portal form validation script with other script

 In your portal form you have form script which is based on your form input. If you also want add form validation in to same script you can use this sample code. $(document).ready(function(){ // Write your other form script code // Client validation this will trigger during submit or next button for advance form window.webFormClientValidate = function () { // write your client validation logic var assistenstd = parseFloat($('#proevt_assistenstd_discount').val()) var filePath = $('#AttachFile').val(); if(assistenstd>0){ if(filePath){ return true; } else { // Validation error alert("Please upload document."); return false; } } }; });

D365 portal please wait bar with animation

 if you want to use please wait with animation in your portal in any event you can use this  this jquery will work with the default bootstrap of the portal.  // Please wait function showPleaseWait() { if (document.querySelector("#pleaseWaitDialog") == null) { var modalLoading = '<div class="modal" id="pleaseWaitDialog" data-backdrop="static" data-keyboard="false" role="dialog">\ <div class="modal-dialog">\ <div class="modal-content">\ <div class="modal-header">\ <h4 class="modal-title">Bitte warten...</h4>\ </div>\ <div class="modal-body">\ <div class="progress">\ <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar"\

D365 portal checkbox enable / disable

Checkbox is special input type into javascript. You can try the following for checkbox enable / disable //Disable $("#std__assistenzarzt").attr('disabled', 'disabled'); $("#std__assistenzarzt").attr("readonly", "readonly"); //Enable $("#std__assistenzarzt").removeAttr('disabled'); $("#std__assistenzarzt").removeAttr('readonly');

D365 portal advance form get the previous step data in the current step

 Using localStorage in javascript we can easily get the previous step data in the current step. // Set value into previous step window.localStorage.setItem('studentregistrationadvancestudentGuid', studentGuid); // Get value into next step var requeststudentId = window.localStorage.getItem('studentregistrationadvancestudentGuid');

D365 portal enable error previewing

 If any error occurs in the portal it is not showing the proper reason for the error. If you enable EnableCustomPluginError it will show the proper message of the error. Go to Site settings and create new : Site/EnableCustomPluginError

d365 portal many to many relationship table permissions

 Sometimes we need to access many to many table relationship access. By default, the portal is not allowing to give permission many to many tables because there is no physical Entity.  Using  Levelup-for-Dynamics-CRM  you can easily set the many to many table permission.  Navigate to your table permission menu into portal enable God Mode Select new, select any entity. Replace the table name with your many-to-many relationship table name. Add web role for this table access

d365 portal fetchxml query as a json service

 In D365 portal sometimes we need to write a complex query which is not covered by List as OData Feed. If you use D365 Form Liquid fetchxml query is also not supported. You can write any fetch xml query as JSON data service into the portal. 1. Create Web Template Into your web template, you need to write your fetchxml query {% assign std_discountid = request.params['id'] %} {% fetchxml discountAccount %} <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="std_std_discount_account_membership" > <attribute name="accountid" /> <attribute name="std_discountid" /> <filter> <condition attribute="std_discountid" operator="eq" value="{{std_discountid}}" /> </filter> </entity> </fetch> {% endfetchxml %} { "accountdiscounts" :

D365 portal field change event set other field value

 if you need to get value from any field into the portal and set other field values you can use this script $(document).ready(function(){ $('#student_couponcode').on('change',(studenteventdiscountamount) => { debugger; var eventcouponcode = studenteventdiscountamount.target.value; var eventcouponcodefilteroption = "student_couponcode eq '"+eventcouponcode+"'"; var odataUrI = "https://yourportal.com/_odata/student_discounts?$filter="+encodeURIComponent(eventcouponcodefilteroption); $.ajax({ type:'GET', contentType: 'application/json; charset=utf-8', datatype: 'json', url: odataUrI, beforeSend: function(XMLHttpRequest){

D365 portal select lookup field value on form load

 If you want to select your lookup field on form load or other events you can use this script. $(document).ready(function(){ var requeststudentId = '{{ request.params.id }}'; if(requeststudentId) { var eventLookupfilteroption = "studentid eq guid'"+requeststudentId+"'"; var odataUrI = "https://yourpotal.com/_odata/students?$filter="+encodeURIComponent(eventLookupfilteroption); $.ajax({ type:'GET', contentType: 'application/json; charset=utf-8', datatype: 'json', url: odataUrI, beforeSend: function(XMLHttpRequest){ XMLHttpRequest.setRequestHeader('Accept', 'application/json'); }, async: true, success: function(data, textStatus, xhr){ if(data.value[0]) { // Populate lookup field var studentid = data.value[0].studentid; v

D365 portal OData query filter

  I am using this OData query filter in my D365 portal. For Guid filtering var userId = '{{ user.id }}'; var contactfilteroption = "contactid eq guid'"+userId+"'"; var odataUrI = "https://yourportal.com/_odata/contacts?$filter="+encodeURIComponent(contactfilteroption); For string filtering var couponcode = eventdiscountamount.target.value; var couponcodefilteroption = "stdsscouponcode eq '"+couponcode+"'"; var odataUrI = "https://yourportal.com/_odata/stdssdiscounts?$filter="+encodeURIComponent(couponcodefilteroption);

D365 portal remove bar from read only field

 If we define a field read-only into CRM and into the portal it shows (-). if you want to remove the bar you can use the following javascript for that field.  $(document).ready(function(){ $("#stdsscode").attr("readonly", true); setTimeout( function(){$("#stdsscode").next("div").hide()}, 300); });

D365 portal set option set value

 In the D365 portal, you can set option set value using javascript. var salutationTitle = data.value[0].stdss_salutation_opt.Name; $("select#stdss_salutation_opt option").filter(function() { return $(this).text() == salutationTitle; }).prop('selected', true);

D365 Error converting attribute value to Property

 You are getting this error into your plugin  Unable to cast object of type 'System.Guid' to type 'Microsoft.Xrm.Sdk.EntityReference' Your crud operation Entity field has a Lookup field relationship and it is expecting EntityReference. EntityReference conactEntityReference = new EntityReference { Id = newContactEntity.Id, LogicalName = Contact.EntityLogicalName }; localContext.OrganizationService.Update(new Entity(proevt_eventregistration.EntityLogicalName, inputEventseriesEntity.Id) { ["proevt_contactid"] = conactEntityReference });  

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) {

D365 Calculate unitwise product quantity into Opportunity field using javascript

  function CalculateOpportunityProductQuantity(executionContext) { var formContext = executionContext.getFormContext(); var opportunityRecordId = formContext.data.entity.getId().slice(1, -1); var globalContext = Xrm.Utility.getGlobalContext(); // Retrive unitwise product quantity data var fetchXml = "<fetch mapping='logical' >" + "<entity name= 'opportunity' >"+ "<link-entity name='opportunityproduct' from='opportunityid' to='opportunityid' alias='opportunityprod' >"+ "<attribute name='quantity' />"+ "<filter>"+ "<condition attribute='opportunityid' operator= 'eq' value='" + opportunityRecordId + "' uiname='Will be ordering' uitype='opportunity' />"+ "</filter&

Dynamics 365 Set a Lookup Field Using JavaScript from another lookup selection change

 In my case, I will select a contact from lookup and it will fill the account lookup field. function OnContactChange(executionContext) { var formContext = executionContext.getFormContext(); if (formContext.getAttribute("parentcontactid").getValue() != null) { var CustomerId = formContext.getAttribute("parentcontactid").getValue()[0].id.slice(1, -1); var CustomerName = formContext.getAttribute("parentcontactid").getValue()[0].name; var CustomerType = formContext.getAttribute("parentcontactid").getValue()[0].entityType; // Call contact API Xrm.WebApi.retrieveRecord("contact", CustomerId, "?$select=_parentcustomerid_value").then( function success(contactresult) { // Call Account Xrm.WebApi.retrieveRecord("account", contactresult._parentcustomerid_val

Dynamic 365 Preview note file attachments

 To preview note attachment i use PCF control. In my PCF control based on entity Id it loads is corresponding note file like : pdf, docs and other into a grid. when i will click on preview then it preview the document. To preview document i use https://www.npmjs.com/package/react-file-viewer  this npm package support Images: png, jpeg, gif, bmp, including 360-degree images pdf csv xslx docx Video: mp4, webm Audio: mp3 Into my PCF control i use : Import: const FileViewer = require('react-file-viewer'); react return view: <div> <FileViewer fileType={this.state.filePreviewType} filePath={this.state.filePreviewPath} /> </div> On preview document click event i pass the id private _previewAttachment = (id: string): void => { debugger; // this._refreshData(); this._props.context.webAPI .retrieveRecord( "annotation", id, "?$select=documentbody,filename,filesiz

Solution failed to import: Import Solution Failed: CustomControl with name failed to import with error: Webresource content size is too big.

 In Powerapps i was getting error during import my PCF control. 1. Open the cdsproj file and set the SolutionPackageType = Both. It will generate manage and unmanage solution.    <PropertyGroup>     <SolutionPackageType>Both</SolutionPackageType>   </PropertyGroup>   2. Run the build command with release parameter msbuild /p:configuration=Release