Search This Blog

Showing posts with label Lookup. Show all posts
Showing posts with label Lookup. Show all posts

Monday, September 21, 2015

Retrieve record from related entity using XrmServiceToolkit javascript in crm 2013/2015

Download XrmServiceToolkit from here
Extract and upload these files into CRM as javascript webresource and also Add on the form where you need to retrieve
1. Json2
2. jquery
3. XrmServiceToolkit

Code: In this code i retrieve description field from related entity

function get_details()
{
var Courselookup=null;
var coursetitle_name=null;
var CourselookupId=null;

 Courselookup = Xrm.Page.data.entity.attributes.get('new_school');
    if (Courselookup.getValue() != null)
    {   
        CourselookupId = Courselookup.getValue()[0].id;   
        var course_obj = Retrieve(CourselookupId);
        if (course_obj.new_Description != null )
        {
            coursetitle_name=course_obj.new_Description;
            Xrm.Page.getAttribute("new_description").setValue(coursetitle_name);
            Xrm.Page.getAttribute("new_description").setSubmitMode("always");
        }
        }
}
function Retrieve(_id) {
    var re;   
    XrmServiceToolkit.Rest.Retrieve(
              _id,
              "new_schoolSet",
              null, null,
              function (result) {
                  re = result;                
              },
              function (error) {
                  alert("failed");
              },
              false
          );
          return re;
}



Saturday, October 25, 2014

Filter Lookup values in CRM 2011 and CRM 2013 without Javascript

In this Example I filter cities of a country. Follow following steps:

  •  Every country have many cities, so i create a 1:N relationship of cities with country entity i.e. in city entity i have lookup of country entity. 
  • Now in Account entity i create two lookups one of Country entity and second city entity.

  • In city entity I added some sample records of cities and also select their country so that city will be filtered related to that country.                                                                                     



  • Now open lookup of city and edit filter record settings as shown in below image. 





  • Filtered records are shown below that When I select country Pakistan only cities related to Pakistan are shown and when I select country Afghanistan only cities related to Afghanistan are shown.                                                                                                                                  















Tuesday, January 21, 2014

Dialog to write comment and select a user from Lookup to send email with comment to the user selected in Lookup

Start dialog on entity on Contact entity.
Follow these steps:

    1.Add step page
    2.Add step Prompt and response. From this prompt and response we create comment box to get comment from user. Click on set properties. I select multiline text for comment.          
                     
   4.    Now add another Prompt and response to select user. Now in this I will make a Lookup of all user        belong to this organization. Click on set properties and set those properties which are set in below       screen shot.

5. Now we send email to the user which we select from lookup and also comment is added in the subject of     this email. Add send email step now click on set properties.
  • In From: In right side select the name of user you set like in this case Sendto (user) then from its below drop down select created by no click add then click on from text box and press OK. So that {created By (Sendto (user))}.
  • In To: In right side select the name of user you set like in this case Sendto (user) then from its below drop down select User no click add then click on from text box and press OK. So that {User (Sendto (user))}.
  • Now to add comment in Detail of email: Select Comment Please from above drop down the name of comment you set in this case Comment please and then from below drop down select Response Text. So that {Response Text (Comment Please)}. 








Friday, December 6, 2013

Get lookup value and also set into other field

var P_lookupValue = new Array();             
P_lookupValue[0] = new Object();
P_lookupValue[0].id = lookup.Id;
P_lookupValue[0].name = lookup.Name;
P_lookupValue[0].entityType = "lookup_name";
              
Xrm.Page.getAttribute("field_name").setValue(lookupValue); //set lookup value into field
Xrm.Page.data.entity.attributes.get("field_name").setSubmitMode("always"); // this line will set value if field is readonly