web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Lookup on load for new form I am getting null

(0) ShareShare
ReportReport
Posted on by 195

Hi friends, i have 2 lookups. i have to get the name from lookups and set name in the name field on onload event. when i click on new form on load i am getting cant read the property null error. please suggest me some solution for this.thanks.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Bharrath,

    Could you please post your code here .

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    It may be your code is trying to get lookup value without checking if it is available or not.

    so make sure your in your code you have validation like below

    if(Xrm.Page.getAttribute('Lookupfieldname')!=null && Xrm.Page.getAttribute('Lookupfieldname').getValue()!=null)

    {

    //only then get value

    }

    If this don't solve your issue, share your code here so that someone can help you.

  • bharrath Profile Picture
    195 on at

    function engagementOnLoad()

    {

    var customerValue = Xrm.Page.getAttribute("pcc_engagement").getValue();

    if(customerValue !=null)

    {

    var name=customerValue[0].name;

    alert(name);

    }

    else

    {

    Xrm.Page.getAttribute("pcc_name").setValue(name);

    }

    }

    function solutionOnLoad()

    {

    var sol = Xrm.Page.getAttribute("pcc_solution").getValue();

    if(sol!=null)

    {

    var sname=sol[0].name;

    //alert(sname);

    }

    else

    {

    Xrm.Page.getAttribute("pcc_name").setValue(sname);

    }

    }

  • bharrath Profile Picture
    195 on at

    this is the code i have written. any changes please let me know. onload getting lookup name and setting in name field

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Why are you assigning value on the else part (where name will be null?), it should be like below:

    function engagementOnLoad()

    {

    var customerValue = Xrm.Page.getAttribute("pcc_engagement").getValue();

    if(customerValue !=null)

    {

    var name=customerValue[0].name;

    Xrm.Page.getAttribute("pcc_name").setValue(name);

    }

    }

    function solutionOnLoad()

    {

    var sol = Xrm.Page.getAttribute("pcc_solution").getValue();

    if(sol!=null)

    {

    var sname=sol[0].name;

    Xrm.Page.getAttribute("pcc_name").setValue(sname);

    }

    }

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Bharath,

    In which form you are getting error , is it Update form or Create Form?

    If  the form type is "create" until and unless you set any value in the lookup field you wont get any name from the lookup , so make sure you first set the lookup value  before get the name in the Create Form.

    As  Mahendar already pointed that in the else part in your code it will enter only when you will get lookup is null and thats why you are getting always null.

    function engagementOnLoad() {
        if (Xrm.Page.ui.getFormType() == 2) { // Update Form
            var customerValue = Xrm.Page.getAttribute("pcc_engagement").getValue();
    
            if (customerValue != null && customerValue != undefined) {
                var name = customerValue[0].name;
                Xrm.Page.getAttribute("pcc_name").setValue(name);
            }
        }
        else
        {
             
            // Set lookup value first 
    
            // Get lookup name 
    
            // Set the lookup name value to text
        }
    
    }
    
    function solutionOnLoad() {
        if (Xrm.Page.ui.getFormType() == 2) { //Update form
            var sol = Xrm.Page.getAttribute("pcc_solution").getValue();
            if (sol != null && sol != undefined) {
                var sname = sol[0].name;
                Xrm.Page.getAttribute("pcc_name").setValue(sname);
            }
        }
        else
        {
            // Set lookup value first 
    
            // Get lookup name 
    
            // Set the lookup name to the text
    
        }
    }


    Hope this helps 

  • bharrath Profile Picture
    195 on at

    This is working fine. thank u very much mahender

  • bharrath Profile Picture
    195 on at

    Thanks Goutam.  Below code is working fine. Thanks u very much.

    function engagementOnLoad()

    {

    var customerValue = Xrm.Page.getAttribute("pcc_engagement").getValue();

    if(customerValue !=null)

    {

    var name=customerValue[0].name;

    Xrm.Page.getAttribute("pcc_name").setValue(name);

    }

    }

    function solutionOnLoad()

    {

    var sol = Xrm.Page.getAttribute("pcc_solution").getValue();

    if(sol!=null)

    {

    var sname=sol[0].name;

    Xrm.Page.getAttribute("pcc_name").setValue(sname);

    }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans