locked
Javascript Issue RRS feed

  • Question

  • Hi

    I have the following fields on my Contact form:
    - new_firstname  (ex: Elaine)
    - new_lastname   (ex: McKinnon)
    - new_name (which is the new_firstname + new_lastname)

    I have put the following code in
    - OnLoad of Contact Form
    - OnSave of Contact Form
    - OnChange event of new_firstname
    - OnChange event of new_lastname

    So when I save the record or change the first name and last name
    fields the new_name updated accordingly. In this case I changed
    the last name to "Peace"

    This works fine on the Contact Form, however when I go to view the
    grid list of Active Contacts.. Elaine's Last Name is not displaying
    "Peace" - it is displaying the old last name "McKinnon".

    What do I need to do to resolve this issue?


    function updateFullName(firstName, lastName, fullName)
    {
     var fName = Xrm.Page.data.entity.attributes.get(firstName).getValue();
     var lName = Xrm.Page.data.entity.attributes.get(lastName).getValue();

     if (fName == null)
     {
      fName = "";
     }
            else
     {
      fName =  fName + " ";
     }
     if (lName == null)
     {
      lName = "";
     }
     Xrm.Page.data.entity.attributes.get(fullName).setValue(fName + lName);
    }

     

    Saturday, July 6, 2013 4:14 PM

Answers

  • Is the field you are setting marked as read-only? If so you will need to add a line of script to force it to be submitted to the server when saved. Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    • Marked as answer by katiemackie Saturday, July 6, 2013 8:06 PM
    Saturday, July 6, 2013 7:44 PM
    Moderator

All replies

  • Katie, it seems though you are changing the values on the form correctly but before it gets reflected anywhere you'll have to save it first.

    Just by doing setValue() won't work for the onChange event. Modify your code as mentioned below:

    function updateFullName(firstName, lastName, fullName) {
    	var fName = Xrm.Page.data.entity.attributes.get(firstName).getValue();
    	var lName = Xrm.Page.data.entity.attributes.get(lastName).getValue();
    
    	if (fName == null) {
    		fName = "";
    	} else {
    		fName = fName + " ";
    	}
    	if (lName == null) {
    		lName = "";
    	}
    	Xrm.Page.data.entity.attributes.get(fullName).setValue(fName + lName);
    	Xrm.Page.data.entity.save();
    }
    HTH


    Please don't forget to mark the answer, if it helps. Piyush

    Saturday, July 6, 2013 5:27 PM
  • Hi

    Thanks for helping me.

    I have updated the function in the Contact Form according to your changes above.
    Unfortunately, the Contract Grid List is still displaying the old Last Name "Elaine McKinnon".
    I clicked the refresh button on the grid list and still no changes.

    Katie

    Saturday, July 6, 2013 6:47 PM
  • Is the field you are setting marked as read-only? If so you will need to add a line of script to force it to be submitted to the server when saved. Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    • Marked as answer by katiemackie Saturday, July 6, 2013 8:06 PM
    Saturday, July 6, 2013 7:44 PM
    Moderator
  • function updateFullName(firstName, lastName, fullName)
    {

      Xrm.Page.getAttribute(firstName).setSubmitMode('always');

      Xrm.Page.getAttribute(lastName).setSubmitMode('always');

      Xrm.Page.getAttribute(fullName).setSubmitMode('always');

     var fName = Xrm.Page.data.entity.attributes.get(firstName).getValue();
     var lName = Xrm.Page.data.entity.attributes.get(lastName).getValue();

     if (fName == null)
     {
      fName = "";
     }
            else
     {
      fName =  fName + " ";
     }
     if (lName == null)
     {
      lName = "";
     }
     Xrm.Page.data.entity.attributes.get(fullName).setValue(fName + lName);
    }



    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Monday, July 8, 2013 11:36 AM