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)

get lookup field name

(0) ShareShare
ReportReport
Posted on by 2,665

Hi,

I have this piece of script, which alerts the project name but when I debug the line var projectsName=projects[0].name; shows name as undefined but then it alerts the project name. What does that mean? I used the variable projectName further in my script, which threw an exception saying:

 Expected 'UniqueId' data type for 'new_projects' parameter in 'Request.QueryString'.  The raw request was 'GET /
..............
Also, [FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).]
function getCall(){   
var projects=Xrm.Page.getAttribute("new_projects").getValue();
    if(projects!=null){
    var projectsName=projects[0].name; 
    alert(projectsName);
    }
  
}

I've worked with this lookup field before and I never had this issue!

Thanks for any help.

*This post is locked for comments

I have the same question (0)
  • Royal King Profile Picture
    27,686 on at

    it looks like you want to pass guid in ODATA query but you are passing name of the lookup . replace  projects[0].name with projects[0].id  that may fix the issue.

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi..

    As per exception.. your further code is excepting project GUID not projects name.

    you need to use id instead of name or create another variable and get projectId in it like

    var projectsid=projects[0].id;  or

    var projectsName=projects[0].id;    ---> This will give you GUID / projects Id

    and use this projectsid/projectsName into your code.. where you are trying to open entity form.

    Hope this will help.

  • crmprogrammer2013 Profile Picture
    2,665 on at

    Thanks Chitra,

    I tried projects[0].id, debugging it looks good with retrieving all the values.

    The exception is still thrown on this line of my script.

    Xrm.Utility.openEntityForm("incident", null, parameters);


    This is my script to copy the record field values to new form.

    function getCall()
    {
    debugger;
     //get values from the Form
        var callId = Xrm.Page.data.entity.getId();
        var CallTitle=Xrm.Page.data.entity.attributes.get("title").getValue(); 
        var summary=Xrm.Page.data.entity.attributes.get("description").getValue();
        var project=Xrm.Page.data.entity.attributes.get("new_project").getValue();
        if(project!=null){
        var projectId=court[0].id;
        var projectName=court[0].name;
        var projectType=court[0].entityType; 
        }
      
        var parameters = {};
        if (CallTitle!= null) {
            parameters["title"] =" ";
        }
       if(summary!=null){
        parameters["description"]=summary;
      }
       if(projectId!=null && projectName!=null){
        parameters["projectid"]=projectId;
        parameters["projectname"]=projectName;
        parameters["projecttype"]=projectType;
       }  
     
    //pop incident form with default values
        Xrm.Utility.openEntityForm("incident", null, parameters);
    }


    Thanks.

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    I think you need to pass parameters like

    if(projectId!=null && projectName!=null){

       parameters["new_projectid"]=projectId;

       parameters["new_projectname"]=projectName;

       parameters["new_projecttype"]=projectType;

      }  

    for more details check

    msdn.microsoft.com/.../gg334375.aspx

    msdn.microsoft.com/.../jj602956.aspx

  • Royal King Profile Picture
    27,686 on at

    it looks like attribute names does not have prefix. Check attribute names

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Roxanna,

    In the Incident entity (case)

    You have the fields to capture the parameter or you want to define your own custom query string parameter?

    If they are existing fields, you should make sure that you have the fields in the Case

    Check your lookuname..

    Is this new_projectid or new_projectsid or new_project only..

    Let's say your field name is new_projectid then you should give parameter:

    if(projectId!=null && projectName!=null){

       parameters["new_projectid"]=projectId;

       parameters["new_projectidname"]=projectName;

       parameters["new_projectidtype"]=projectType;

      }

    While if the name of your field lookup is only new_project

    then you should use:

    if(projectId!=null && projectName!=null){

       parameters["new_project"]=projectId;

       parameters["new_projectname"]=projectName;

       parameters["new_projecttype"]=projectType;

      }

    This based on this link.

    See this:

    msdn.microsoft.com/.../gg334375.aspx;MSPPError=-2147217396#BKMK_setValueLookupfields

    So the field name to capture this parameter should be correct.

    With: fieldnameId, fieldnameName, fieldnameType

    But all should be in lower cap.

    "new_project"

    "new_projectname"

    "new_projecttype"

    if the field name = new_project only.

    Hope this helps.

    Thanks.

  • Community Member Profile Picture
    on at

    Hi Aileen,

    I have a similar issue. I am using Dynamics 365. I am trying to copy the entity fields and default in the new form for cloning purpose. Except lookup field on the BPF and multiselectpicklist on the form, I am able to copy all other fields and default it to the new form.

    //Snippet to copy existingcase field from the BPF

    if (attributeName == "existingcase" && attributeType == "lookup") {

                                       //var existingCase = Xrm.Page.getControl("existingcase").getAttribute().getValue();//I tried using "header_process_existingcase" but still did not work

                                       var existingCase = Xrm.Page.getAttribute("existingcase").getValue();

                                       var existingCaseId = existingCase[0].id;

                                       var existingCaseName = existingCase[0].name;

                                       var existingCaseType = existingCase[0].entityType;

                                       if (existingCaseId != null && existingCaseName != null) {

                                           parameters["existingcase"] = existingCaseId;

                                           parameters["existingcasename"] = existingCaseName;

                                           parameters["existingcasetype"] = existingCaseType;

                                       }

                                   }

    I get the value on the LHS but I get an error - CRM Parameter Filter - Invalid parameter 'existingcasename=Clone Record Test 1' in Request.QueryString

    //snipped to copy multiselectpicklist

    else if (attributeType == "multiselectoptionset") {

                                       var options = Xrm.Page.getAttribute(attributeName).getText();//I also tried using getSelectedOption(). Still this did not work

                                       parameters[attributeName] = options;

                                   }

    I get the value on the LHS but I get an error for multiselectpicklist - Newtonsoft.Json.JsonReaderException: Error parsing positive infinity value. Path '', line 0, position 0.

    Any suggestion would be appreciated.

    Regards,

    Ganesh A

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