Dynamics CRM - Add/Remove events from a custom made settings page - javascript

Hi awesome developers,
Maybe someone can help or put me in the right direction. I want to create a settings page with a few yes/no options.
These settings need to enable or disable form events from different entities. First I was thinking about creating a new entity named foo_Settings with a few fields and yes/no options to trigger on change events. These events will then add or remove events from another entity.
After doing some research, I couldn't find any examples or cases or any info if this could be done through webservices.
I hope someone can help :)
Greets,

Yes, it is a common design pattern in CRM to have a settings/configuration-entity for storing settings such as this.
You can decide to either have one settings-record per organization, or maybe one settings-record per business unit if that suits your needs better. In this way you can have different configurations depending on the need of each business unit.
After creating the settings record and adding some boolean fields, you would write javascript that runs OnLoad of specific entities. This code would fetch the relevant settings-record, read the value of the relevant boolean-field and add a change listener depending on the value of the boolean by calling addOnChange().

After thinking about the settingspage and ways/solutions to create such functionality, there also was something that was itchy..
By creating a settings page and checking in the onload function of each entity with a fetch (odata call), this is not the most fastest or cleanest way. What if thousands of people are using a entity.. This will resulting that thousands of people will fetch.
So my solution will be:
Creating a settingspage (entity).. Onchange event of a setting will fire a odata call to set a record (true or false) on a hidden field in that entity..
In the onload of the entity I will check the value of that hidden field and do logic. This way I will prevent that there will be an Odata call every time the page loads..
Are there any other solutions?

Related

get notes input control from timeline via javascript

I would like to be able to hook an onChange event for the default text input box for Notes in a Dynamics CRM timeline (activity feed). However, I am not allowed to manually pull it from the DOM incase breaking changes occur in the future so I was hoping I could find it as a control with fixed name, such as fsdyn_notesinput for example.
However I have been unable to retrieve the specific control I am after. I can find "Timeline" which I believe contains the text control I want but have failed to find a way to enumerate the timeline's children or anything like that.
The intention is for me to be able to live check what is being typed into the box to look for special terms such as tags and provide additional functionality. I am very new to Dynamics development so it may be I am approaching this all wrong!
Currently I have nothing to share other than the typescript timeline fetch, which works:
let test2 = executionContext.getFormContext().getControl("Timeline");
We are using the new unified interface in the cloud.
You cannot hook an event handler to Notes control events in a supported way.
Instead, you can keep a multiline textbox in the entity form & onChange can be triggered on that field - you can provide additional functionality from here. You can create a Note (annotation) record with the content in this multiline field on record save.
In case of Notes creation from activity feed anywhere outside the entity form like dashboard, you should try C# Plugin on Notes record creation.

In Dynamics 365, is there a way to filter associated view results based on a record's field value and user permissions?

As the title states, I need to filter results of an associated view based on a record's field value and user permissions.
I've used some Javascript to achieve this whenever the iFrame loads, but if the user switches to a different view, my Javascript is not called and the filtered records come back. I've tried to implement an event listener for various changes within the iFrame, but haven't been able to get what I need. I've gotten onclick to call my function whenever the user opens the view dropdown, but I need it to call whenever they actually switch views.
Am I over complicating this and there's a native way to do this? Or does anyone know how to detect changes within an iFrame?
Unfortunately there’s no native config to do it by OOB. I recommend these.
Don’t rely on associated view, as the name suggests it’s for seeing all the associated records. Remove navigation item in Form editor to remove them if you don’t want your users to see it
Use Subgrid for all your different needs, but not with view switcher, as again you will get roadblock of view switch triggers, etc. also this is going to be unsupported approach to rig the FetchXml with your custom filters
Custom HTML with grid is better or even PCF control of your own to take query & filters
Plugin on RetrieveMultiple can be used in worst cases

DRY up ng-model

I have a small web-app that accepts input from a human to create search params. I'm using ng-model-options to debounce the ng-change function to execute the search.
I have small arrows next to the column names on the table that lets users sort (there are three icons - up-down, up, and down for the sort_field and sort_order displayed using ng-class) ; I would like to register a change on those and execute a search after a small delay using debounce. The problem is I'm not sure how use ng-model to bind the particular param to those icons. I don't want someone hammering on the sort icons and crashing the server or their browser.
What I would rather do is have one place on the page that says to watch the search_param object and fire a search 500 milliseconds after whenever it has changed. This way any of the input fields or sort selections would be called when a user is done editing them which triggers a function to send those params to the endpoint.
What is the strategy in AngularJS to do this? Right now all input fields bind a field in the search_param object and have ng-model-options to debounce on change. This is a lot of repeated code.
I recently answered someone regarding Tables and the amount of effort and work you have to put in to get very basic functionality (sorting,searching,pagination).
Why re-invent the wheel if there is a perfectly great library for you to use:
Angular-datatables
I posted a complete solution here for you to use pulling data from a json source: Ng-repeat trying to create a counter index
In your case you would need to go through the Server side processing documentation on Datatable's site to correctly format the data: https://datatables.net/manual/server-side

How can I add a picklist to a case form for custom entities (note: replace the normal lookup field)?

I have a requirement that a custom entity 'Priority' is selected on the case form but rather than using the normal lookup method, I want to display a picklist with the priority entitys listed.
One solution I have come up with is to have the lookup field on the form as normal but not set to visible and have a jscript routine add a select to the DOM looking up the required values at using a JSON request. On the selected changed event of the custom select, I can programatically set the value of the lookup.
The problem with this is it's quite messy and not supported.
Is there is a supported way to do what I want and if not, can anyone see any issues with the solution provided?
Settings the value of a lookup with javascript is supported. Custom html controls are suported as web resources. Your solution will work and actually is a supported customization.
As for your other options...
Presumably this request stems from the users thinking it takes "too many clicks and too much time" to select from such a short list of Priority entities. Is it possible your requirements are negotiable? Are your users aware of all two nice features of the lookup: 1. you can type the first few letters of the Priority's name and tab out, and it will auto-complete for you. 2. Similarily you can type just the first couple letters and a dropdown will expand below the lookup with the available options. Its quite fast and you dont need to load a seperate screen which I am assuming is their usability concern.
Alternatively, if they are dead-set on the dropdown, can this Priority data be represented as an optionset? I'm a bit suprised that you needed an entity for Priority concerns, what metadata about priority do you need?

Django Admin disable field dynamically based on other selections

I've built a django model where the required fields change based upon the user's selection on other previous fields. Specifically, it is an event scheduling application where the options change based on choices the user makes.
Some combinations of fields are simply invalid, and I have the model set to check for those and not allow them. However, it is a bit confusing in the UI to figure out the right combinations. I would like the admin UI to help with this by hiding or disabling invalid fields as the user changes other fields.
For example, if the user chooses to make the event repeat weekly, I need to disable (or ideally remove) all of the daily and monthly fields and only show the weekly ones, such as day of week.
Also, if they go back and change it to daily, then the fields that are shown or enabled need to change to reflect that selection.
How would I set up the admin form so that this happens? I know this is doable through the DOM and javascript, but I am trying to determine if there is a mechanism for this built in to Django. I've been searching the Django docs, but I can't seem to find it.
Does anyone have an example showing how you have done similar things?
There's no build in solution.
Simple solution is to add custom JavaScript code to your admin. See the reference here. Simply add the js and css files to the Admin class and script the form in your custom js.
class ReportAdmin(admin.ModelAdmin):
class Media:
js = (
'frontend/js/jquery-1.6.1.min.js',
'frontend/js/jquery-ui.min.js',
'frontend/js/custom_js.js',
)

Categories