Link to home
Start Free TrialLog in
Avatar of afluke
afluke

asked on

CRM 2015 Scripting on Form Fields

I am trying to figure out how to set up a script to run when someone attempts to enter information into the subject line of an email. We have a mail security appliance that sends encrypted messages and one of the ways to bypass this is by adding a special tag at the end of the subject. For example

This is a subject - TAG

I had modified some of the scripts in our CRM 2011 environment but we recently deployed a CRM 2015 environment and none of the old scripts seem to be working. I am wondering if anyone could help me get this to work?

I went to Settings > Customizations > Customize the System > Web Resources

From here I went to New and crated a resource of type Script (JScript) named New_Email_Form_Library (it appended New not sure why, I don't see an existing one). I browsed out to my .js file and uploaded it. I then published all customizations.

Here is a screenshot of the properties of this solution.

 User generated image
So I then went over to the Entites > Email > Forms section went to the Email Form and then selected the Subject field and went to the Events tab and added the library and then set up the event handler as I would have in CRM 2011.
User generated image
So then I use the large + in the ribbon to create an email and when I attempt to input anything into the subject nothing happens. I added a test function which simply runs "alert" and that does not function either. Any ideas?

Below is my Javascript.
function subject_onchange()
{
// Get the field that fired the event.
var oField = Xrm.Page.getAttribute("subject"); // get subject attribute

// Validate the field information. 
if (oField.getValue() != null && oField.getValue() != undefined && oField.getValue() != "");
{
	var x = confirm("I confirm that there is not BLAHBLAH in this email");
	if (x == true);
	{
	oField = oField + " - TAG";
	}
}
}
function test_onchange()
{
alert("test");
}

Open in new window

Avatar of Feridun Kadir
Feridun Kadir
Flag of United Kingdom of Great Britain and Northern Ireland image

Everything you've done looks correct.

One thing to check, which form shows when you create an email? Is it email or wizard?
ASKER CERTIFIED SOLUTION
Avatar of Rikin Shah
Rikin Shah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well spotted!
Avatar of afluke
afluke

ASKER

Yes thank you very much!

That was in fact the problem, removing the parens worked like a charm. Thank you all for your time!