Thursday, 28 May 2015

javascript for Fetch the data from lookup an and set the value for field on Form in ms crm

1. I have created teacher Entity In my Ms crm solution  and added following field in it

  • FirstName
  • LastName
  • Birthdate
  • Gender
  • salary
  • ContatcNo
  • Married
  • age
  • teaching area


2. second step i have created School entity in this entity i have created same field as of teacher entity
and add on extra lookup call TeacherDetails



after that i have written following  script for Fetching Data and Call that Script On Onchange Of Teacher Details Event.

3.function OnchnageOfLookup() {

    var lookupid = GetIdFromLookup("new_teachersdetails");

    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> " +
            " <entity name='new_teacher'> " +
            "<attribute name='new_firstname' />" +
            "<attribute name='new_lastname' />" +
            "<attribute name='new_birthdate' />" +
            "<attribute name='new_gender' />" +
            "<attribute name='new_salary' />" +
            "<attribute name='new_contactno' />" +
            "<attribute name='new_married' />" +
            "<attribute name='new_teachingarea' />" +
            "<attribute name='new_age' />" +
            "<attribute name='new_teacherid' />" +
            " <filter type='and'> " +
            "  <condition attribute='new_teacherid' operator='eq' value='" + lookupid + "' /> " +
             " </filter> " +
              "</entity> " +
                "</fetch>";


    Result = XrmServiceToolkit.Soap.Fetch(fetchXML);

    var FirstName = Result[0].attributes.new_firstname.value;
    SetTextFieldValue("new_firstname", FirstName);

    var lastname = Result[0].attributes.new_lastname.value;
    SetTextFieldValue("new_lastname", lastname);

    var bday = Result[0].attributes.new_birthdate.value;
    SetTextFieldValue("new_birthdate", bday);


    var gender = Result[0].attributes.new_gender.value;
    SetTextFieldValue("new_gender", gender);

    var salary = Result[0].attributes.new_salary.value;
    SetTextFieldValue("new_salary1", salary);


    var contact = Result[0].attributes.new_contactno.value;
    SetTextFieldValue("new_contactno", contact);

    var married = Result[0].attributes.new_married.value;
    SetTextFieldValue("new_married", married);

    var tarea = Result[0].attributes.new_teachingarea.value;
    SetTextFieldValue("new_teachingarea", tarea);

    var age = Result[0].attributes.new_age.value;
    SetTextFieldValue("new_age", age);

}

4.Save and Publish it.

5.the Output will look like this




No comments:

Post a Comment