Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

onChange and onSave in one form?

$
0
0

I need your help again. This time on JScript or better: how get onChange and onSave in one form to run.

So we got at our account-form a JScript which sets a search field to a predefined value. This search field is a new entity. Everything works fine. The user saves a new account without setting the country. On save the country is automatically set to "Germany".
On our contact-form we have a JScript which sets a field with onChange to a defined value. Here is also everything fine. The user has to choose between "male" and "female". In case he chose "male" the salutation is "Sehr geehrter Herr...".

I tried now to combine both on contact form. I copied the JScript from account form and changed the names. Saved it as a new webressource and added it to the form. But even the pure presence seems to make the onChange event dizzy. I get a warning: "Error in userdefined event. Field: gendercode, event: onchange, Error: The object doesn't support the method "OnGendercodeChange"."

It doesn't matter if I declare the functions (the ContactFormLib.UIResponse.OnGendercodeChange for on change on salutation field and ContactFormLib.UIResponse.OnContactSave on the form) in event handler. The error is still the same.

This is the JScript for onChange:

if (typeof (ContactFormLib) == "undefined")
{ ContactFormLib = {}; }
// Create Namespace container for functions in this library;
ContactFormLib.UIResponse = {

	OnContactSave: function () {
	 
		  if (Xrm.Page.getAttribute("dcs_countries").getValue() == null)
		  {
			var lookupData = new Array();
			var lookupItem = new Object();
			lookupItem.id = '{6CCCF7AC-5127-E211-B3EB-3C4A92DBC8C7}';                              
			lookupItem.typename = 'NEW_COUNTRIES';
			lookupItem.name = 'Deutschland';
			lookupData[0] = lookupItem;
			Xrm.Page.getAttribute("dcs_countries").setValue(lookupData);
			}
		  }
};

And this is for onSave:

if (typeof (ContactFormLib) == "undefined")
{ ContactFormLib = {}; }
// Create Namespace container for functions in this library;
ContactFormLib.UIResponse = {

    OnGendercodeChange: function () {

        var stSalutationSuffix;
        var stCurrSalutation = Xrm.Page.getAttribute("new_lettersalutation").getValue();
        var stFirstName = Xrm.Page.getAttribute("firstname").getValue();
        var stLastName = Xrm.Page.getAttribute("lastname").getValue();
        var stFullName = Xrm.Page.getAttribute("fullname").getValue();

        if (stCurrSalutation == null) stCurrSalutation = "";
        if (stFirstName == null) stFirstName = "";
        if (stLastName == null) stLastName = "";
        if (stFullName == null) stFullName = stFirstName + " " + stLastName;
        if (Xrm.Page.getAttribute("new_academicsalutation").getValue() != null)
        {
           stSalutationSuffix = Xrm.Page.getAttribute("new_academicsalutation").getValue()[0].name + " "; 
         }
        else
        {
           stSalutationSuffix = ""; 
        }
	if ( stCurrSalutation.indexOf("Sehr geehrter Herr") == 0 ||
	   stCurrSalutation.indexOf("Sehr geehrte Frau") == 0 ||
                        stCurrSalutation.indexOf("Sehr geehrte(r)") == 0 || stCurrSalutation == "" )
        {
            switch (Xrm.Page.getAttribute("gendercode").getValue()) {
                case 1: Xrm.Page.getAttribute("new_lettersalutation").setValue("Sehr geehrter Herr " + stSalutationSuffix);
                    break;

                case 2: Xrm.Page.getAttribute("new_lettersalutation").setValue("Sehr geehrte Frau " + stSalutationSuffix);
                    break;

                default: Xrm.Page.getAttribute("new_lettersalutation").setValue("Sehr geehrte(r) " + stSalutationSuffix);
            }
        }
    }
};


Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>