locked
Java script Appointment entity - pick list field RRS feed

  • Question

  • Hi,

    can anyone help me with a Java Script for CRM 2011?

    In the Appointment entity, I need that:

    IF  the Regarding field contains a "LEAD" type of record,  a pick list field is updated with option 1;  in case the Regarding field contains an "ACCOUNT" type of record,  the pick list field is updated with option 2.

    Thanks for your help in advance, much appreciated!!!!

    Silvia

    Tuesday, April 3, 2012 12:07 PM

Answers

  • function onRegardingFieldChange()

    {
    var lookupObject = Xrm.Page.getAttribute("yourlookupattributename");    if (lookupObject != null) {      var lookUpObjectValue = lookupObject.getValue();  if ((lookUpObjectValue != null))       { var lookuptextvalue = lookUpObjectValue[0].name;          var lookupid = lookUpObjectValue[0].id;          var lookupEntityname = lookUpObjectValue[0].entityType; } } if(lookupEntityname == 'Lead') {

        var Ent = Xrm.Page.data.entity.attributes.get("schemaname_optionSet"); 
        Ent.setValue(1); 

    } else if(lookupEntityname == 'Account') {

        var Ent = Xrm.Page.data.entity.attributes.get("schemaname_optionset"); 
        Ent.setValue(2); 

    } }

    for setting OptionSet value please check this blog.


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Muhammad Mubasher, CRM Developer, The CRM Solutions Pvt Ltd.
    My Blogs: http://mubashersharif.blogspot.com
    My Linkedin: http://pk.linkedin.com/pub/muhammad-mubasher/34/548/305
    My Twitter: https://twitter.com/#!/mubashersharif

    Tuesday, April 3, 2012 1:01 PM
  •  Hi ,

    You can try the below script

    var lookupObject = Xrm.Page.getAttribute("yourlookupattributename");
        if (lookupObject != null)
      {
            var lookUpObjectValue = lookupObject.getValue();
            if ((lookUpObjectValue != null))

            {

             var lookuptextvalue = lookUpObjectValue[0].name;
             var lookupid = lookUpObjectValue[0].id;

             var lookupEntityname = lookUpObjectValue[0].entityType;

            }

      }

    The first will give you the Text value, the second will give the Guid and the third will give you the Entity name.

    You can check which entity is the selected record and then update the picklist accordingly.

    Hope this helps,

    Tuesday, April 3, 2012 12:36 PM
  • Hi,

    Try this.

    if(lookupEntityname == 'lead')
    {
    var Ent = Xrm.Page.data.entity.attributes.get("scapa_accounttype");

    Ent.setValue(1);
    }
    else if(lookupEntityname == 'account')
    {
    var Ent = Xrm.Page.data.entity.attributes.get("scapa_accounttype");

    Ent.setValue(2);
    }


    Regards, Kyaw Kyaw Tun


    Wednesday, April 4, 2012 1:27 AM

All replies

  •  Hi ,

    You can try the below script

    var lookupObject = Xrm.Page.getAttribute("yourlookupattributename");
        if (lookupObject != null)
      {
            var lookUpObjectValue = lookupObject.getValue();
            if ((lookUpObjectValue != null))

            {

             var lookuptextvalue = lookUpObjectValue[0].name;
             var lookupid = lookUpObjectValue[0].id;

             var lookupEntityname = lookUpObjectValue[0].entityType;

            }

      }

    The first will give you the Text value, the second will give the Guid and the third will give you the Entity name.

    You can check which entity is the selected record and then update the picklist accordingly.

    Hope this helps,

    Tuesday, April 3, 2012 12:36 PM
  • function onRegardingFieldChange()

    {
    var lookupObject = Xrm.Page.getAttribute("yourlookupattributename");    if (lookupObject != null) {      var lookUpObjectValue = lookupObject.getValue();  if ((lookUpObjectValue != null))       { var lookuptextvalue = lookUpObjectValue[0].name;          var lookupid = lookUpObjectValue[0].id;          var lookupEntityname = lookUpObjectValue[0].entityType; } } if(lookupEntityname == 'Lead') {

        var Ent = Xrm.Page.data.entity.attributes.get("schemaname_optionSet"); 
        Ent.setValue(1); 

    } else if(lookupEntityname == 'Account') {

        var Ent = Xrm.Page.data.entity.attributes.get("schemaname_optionset"); 
        Ent.setValue(2); 

    } }

    for setting OptionSet value please check this blog.


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Muhammad Mubasher, CRM Developer, The CRM Solutions Pvt Ltd.
    My Blogs: http://mubashersharif.blogspot.com
    My Linkedin: http://pk.linkedin.com/pub/muhammad-mubasher/34/548/305
    My Twitter: https://twitter.com/#!/mubashersharif

    Tuesday, April 3, 2012 1:01 PM
  • Hi Muhammad,

    I have tried to put it in place replacing my fields as you see below, but it does not work. It does not give any Javascript error, but it does not do anything in the form...what's wrong? This is what I entered, on the Regarding Field, on change. Maybe I made a mistake somewhere, I am really a beginner with JavaScript

    function onRegardingFieldChange()
    {
    var lookupObject = Xrm.Page.getAttribute("regardingobjectid");
    if (lookupObject != null)
    {    
    var lookUpObjectValue = lookupObject.getValue();
    if ((lookUpObjectValue != null))
    {
    var lookuptextvalue = lookUpObjectValue[0].name;
    var lookupid = lookUpObjectValue[0].id;
    var lookupEntityname = lookUpObjectValue[0].entityType;
    }
    }
    if(lookupEntityname == 'Lead')
    {
    var Ent = Xrm.Page.data.entity.attributes.get("scapa_accounttype");Ent.setValue(1);
    }
    else if(lookupEntityname == 'Account')
    {
    var Ent = Xrm.Page.data.entity.attributes.get("scapa_accounttype");Ent.setValue(2);
    }
    }

    Tuesday, April 3, 2012 5:23 PM
  • Hi,

    Try this.

    if(lookupEntityname == 'lead')
    {
    var Ent = Xrm.Page.data.entity.attributes.get("scapa_accounttype");

    Ent.setValue(1);
    }
    else if(lookupEntityname == 'account')
    {
    var Ent = Xrm.Page.data.entity.attributes.get("scapa_accounttype");

    Ent.setValue(2);
    }


    Regards, Kyaw Kyaw Tun


    Wednesday, April 4, 2012 1:27 AM