locked
Dependent Picklist based on Owner or Team RRS feed

  • Question

  • Hello, I am using CRM 4 and have used the CRM demonstration tools to create a dependent picklist with two picklist fields on my lead form.  works great.  the next step, however, is to make this dependent on the user/owner or team that owns the record.  For instance, the dependent picklists work like:

    Field 1 value = Social Media

    Dependent Field 2 options are now:  Facebook, Twitter, LinkedIn

    this is currently the scenario for all users.  But now if i want to say, if user 1 has the record open and chooses "Social Media" for Field 1, then Dependent Field 2 should ONLY show Facebook and Twitter.  But for user 2, maybe it should show Twitter and LinkedIn.

    Here is my current (working) code, but need to add this additional step.

    //  Used to help search the picklist items
    Array.prototype.Contains = function(o) 
    {
    var iLength = this.length;

    for (var i = 0; i < iLength; i++)
    {
    if (o == this[i])
    {
    return true;
    }
    }

    return false;
    };

    // This is the main function that will filter the picklists
    crmForm.FilterPicklist = function x()
    {
    var oPrimaryPicklist = crmForm.all.leadsourcecode;
    var oRealatedPicklist = crmForm.all.new_referredbypick;

    if (oPrimaryPicklist.DataValue == null)
    {
    oRealatedPicklist.DataValue = null;
    oRealatedPicklist.ForceSubmit = true;
    oRealatedPicklist.Disabled = true;


    return;
    }


    var oTempArray = new Array();

    var iLength = oRealatedPicklist.originalPicklistOptions.length;

    var aCurrentType = new Array();


    switch (oPrimaryPicklist.DataValue)
    {
    case "200016":
    aCurrentType = new Array(50,51,52,53,54,55,80,81,82,83,84);

    break;
    case "200026":
    aCurrentType.push(62);

    break;
    case "2":
    aCurrentType = new Array(29,30,31);
    break;
    case "31":
    aCurrentType.push(63);

    break;
    case "34":
    aCurrentType = new Array(46,47,48,49);

    break;
    case "4":
    aCurrentType = new Array(56,60);

    break;
    case "200027":
    aCurrentType.push(61);

    break;
    case "200090":
    aCurrentType = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,64,65,66,67,68,69,70,71,72,85,87,88,89,90,91,92,93,94,95,96,97,98);

    break;
    case "22":
    aCurrentType.push(56);

    break;
    case "200092":
    aCurrentType = new Array(43,44,45);

    break;
    case "200005":
    aCurrentType = new Array(32,33,77,99);

    break;
    case "39":
    aCurrentType.push(57);

    break;
    case "200004":
    aCurrentType = new Array(38,39,40,41,42);

    break;
    case "32":
    aCurrentType.push(58);
    break;
    case "200022":
    aCurrentType.push(59);

    break;
    case "200091":
    aCurrentType = new Array(34,35,36,37,76,78,79,100);

    break;
    }


    for (var i = 0; i < iLength; i++)
    {
    if (aCurrentType.Contains(oRealatedPicklist.originalPicklistOptions[i].DataValue))
    {
    oTempArray.push(oRealatedPicklist.originalPicklistOptions[i]);
    }
    }

    oRealatedPicklist.Options = oTempArray;

    if (oTempArray.length > 0)
    {
    oRealatedPicklist.Disabled = false;
    }
    else
    {
    oRealatedPicklist.DataValue = null;
    oRealatedPicklist.ForceSubmit = true;
    oRealatedPicklist.Disabled = true;
    }
    }

    var CRM_FORM_TYPE_CREATE = 1;
    var CRM_FORM_TYPE_UPDATE = 2;

    switch (crmForm.FormType)
    {
    case CRM_FORM_TYPE_CREATE://CREATE_FORM - try these and blow away the vars above
    case CRM_FORM_TYPE_UPDATE: //UPDATE_FORM

    var oRealatedPicklist = crmForm.all.new_referredbypick;

    oRealatedPicklist.originalPicklistOptions = oRealatedPicklist.Options;

    if (crmForm.all.leadsourcecode.DataValue == null)
    {
    oRealatedPicklist.Disabled = true;
    }
    else
    {
    var iPicklistValue = oRealatedPicklist.DataValue;
    crmForm.FilterPicklist();
    oRealatedPicklist.DataValue = iPicklistValue;
    }

    break;
    }

    Thanks!

    Thursday, December 19, 2013 9:21 PM