locked
Jscript needed RRS feed

  • Question

  • Hello,

    Can someone help me write a jscript for CRM2011 that would set a Date Field to Required if a lookup field contains data?

    The date field is called "new_forecastedestimatecompletiondate" and the Lookup field is called "new_estimatepreparedbyid"

    Thank you!

    Friday, November 2, 2012 3:30 PM

Answers

  • Hi,

    This is a good reference page for things like this: 

    http://msdn.microsoft.com/en-us/library/jj602964.aspx


    Something like the following. 

    var lookup = Xrm.Page.getAttribute("new_estimatepreparedbyid");
    var dateField = Xrm.Page.getAttribute("new_forecastedestimatecompletiondate");
    var lookupValues = lookup.getData();
    var lookupContainsData = (lookupValues !=null) && (lookupValues.length>0);
    if (lookupContainsData)
       dateField.setRequiredLevel("required");
    else
       dateField.setRequiredLevel("none");

    Put this code in the onload and onchange of the lookup field.

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"



    Friday, November 2, 2012 4:14 PM
    Answerer

All replies

  • Hi,

    This is a good reference page for things like this: 

    http://msdn.microsoft.com/en-us/library/jj602964.aspx


    Something like the following. 

    var lookup = Xrm.Page.getAttribute("new_estimatepreparedbyid");
    var dateField = Xrm.Page.getAttribute("new_forecastedestimatecompletiondate");
    var lookupValues = lookup.getData();
    var lookupContainsData = (lookupValues !=null) && (lookupValues.length>0);
    if (lookupContainsData)
       dateField.setRequiredLevel("required");
    else
       dateField.setRequiredLevel("none");

    Put this code in the onload and onchange of the lookup field.

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"



    Friday, November 2, 2012 4:14 PM
    Answerer
  • Try this code:

    function setRequirementlevel()

    {

    var lookup = Xrm.Page.getAttribute("new_estimatepreparedbyid").getValue();

    if(lookup != null) {

    Xrm.Page.getAttribute("new_forecastedestimatecompletiondate").setRequiredLevel(“required”);

    }

    }


    Naren


    • Edited by Naren MN Saturday, November 3, 2012 5:40 AM
    Saturday, November 3, 2012 5:39 AM