Any CRM2011/JavaScript experts?

Soldato
Joined
1 Feb 2006
Posts
8,188
I'm working on some scripts for a CRM 2011 project and it really is a tedious task. The only way to upload scripts is by copying the code into a basic text editor and saving it as a web resource.

I have a number of functions which do basic show/hide stuff but the thing I hate is that you have to go into a given field in design view, click on the properties for that field and then add the event to the onchange function (all this is done by far too many clicks).

An example... on a given dropdown list I may call a function called MyFieldInit...

Code:
function MyFieldInit() {
    //do something here
}

Now, instead of me having to add this method in design view I'd like to be able to add the function to run 'onchange' during the page load code.

In the past I have used jQuery to do some stuff on page load like associating a given dropdown with a given function. The problem I can see is around getting and setting the events on a CRM page. The code is something like:

Code:
Xrm.Page.getAttribute("my_field_name").getValue();

or

Xrm.Page.getControl("my_field_name").setVisible(false);

Is there any way I could use jQuery with these Xrm.Page items to assign associations on page load rather than having to do it to each item in my design view? I have tried using the .setValue("onchange", functioname) but that didn't appear to work. I think not all javascript will work...it seems to be very picky.

Hopefully someone can make sense of this!
 
Is this a HTML/Javascript type issue? or something much more fancy?

I've never used CRM2011, nor do I know what it is exactly :P

If it's web-based, then you should be able to add Events to objects however you like (although setValue probably isnt the best way,using addEventListener() or attachEvent() or something that uses whatever is available would be better).

Does Xrm.Page.getControl() return a HTMLElement? or is it just an object that is on top of it?

If it doesnt provide direct access to the element then hopefully the "my_field_name" is a name or id attribute, which you can access using regular dom functions.

Also Xrm.Page might not be accessible when onload is run, so you might need to have something wait for it to become available. (this might just be from my greasmonkey days though)

Hope anything I've said makes sense :)
 
sorry i can be of no help but i was intregued by what CRM2011 was, that looks bloody evil software! After spending 20mins reading microsofts website, i still can't work it out...

Is it a combination of office365 and sharepoint with added analytic's?

Can you show us the code from one of these XRM pages? i've worked quite extensively with Jquery in the past, but without seeing code i can't picture what its doing.
 
CRM2011 is used mostly for case management type stuff. This is the first time I used it. It is available as an on premise or hosting online by MS. The online version seems very slow though and MS don't offer any SLAs as far as I know. It certainly isn't related to SharePoint at all.

We are using it to create forms that admins will take on the road, visit homes, fill in a form, then sync it back up to the server. You begin by creating all the entities and then creating forms for entering the data. It is evil like you say but it is much quicker to get a simple solution up and running than custom coding would be.

A sample function would be a simple thing like showing/hiding a given field based on a checkbox value:

Code:
function ShowHideField(initField, hideField) {
	var o = Xrm.Page.getAttribute(initField).getValue();
	if (o ==true) {
		Xrm.Page.getControl(hideField).setVisible(true);
	}
	else {
		Xrm.Page.getControl(hideField).setVisible(false);
	}
}

At the moment to enable this functionality for a given field onchange event I would need to open a form in design view, double click the desired field, and then add an onchange event (requires a few clicks).

Instead I want to associate all functions with the required fields on page load/ing. The problem is that you can't even view page source so you can't tell what the real id of an element is. I have no idea if the id corresponds to the field name in design view. I'm sure some tools like firebug might enable source viewing but I haven't tried.
 
Back
Top Bottom