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)

Set lookup using JavaScript from a child Window

(0) ShareShare
ReportReport
Posted on by

Hi there,

In my CRM 2016 8.1.0.359, I have an IFRAME which contains an HTML WebResource (a webpage with a simple button) on the main form of the entity "incident".

If I create a new incident (without saving it!) and then I click on this button, I open a new window (another HTML Page) in which I implemented a custom search using a 3th part web service.

When I found the record I need, I click on it and I want to set it into the lookup "customerid"

This is my fragment of code for creating the value to put into the lookup:

var object = new Array();
object[0] = new Object();
object[0].id = "{" + value + "}";
object[0].name = entityDisplayValue;
object[0].entityType = entityName;


where value contains a GUID without the brench, entityName can be "account" or "contact" and entityDisplay name of the account or the contact.

At this point I tried the following 3 lines of code but without success:

window.parent.opener.parent.Xrm.Page.getAttribute("customerid").setValue(object);
window.opener.parent.Xrm.Page.getAttribute("customerid").setValue(object);
window.opener.parent.Xrm.Page.data.entity.attributes.get("customerid").setValue(object)	

if I go in debug and I stop to the "getAttribute" I see in the console that the attribut is recognized but the .setValue do not have any effect and a .getValue always return null.

How can I solve this problem? Do you have any hints?

Thanks in advance for your help!

Gennaro

*This post is locked for comments

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

    Hi Gennaro,

    Can you write below code

    var lookupValue = new Array();

       lookupValue[0] = new Object();

       lookupValue[0].id = Xrm.Page.data.entity.getId();

       lookupValue[0].name = Xrm.Page.data.entity.attributes.get("firstname").getValue()+" " +Xrm.Page.data.entity.attributes.get("lastname").getValue();

       alert(Xrm.Page.data.entity.attributes.get("firstname").getValue()+" " +Xrm.Page.data.entity.attributes.get("lastname").getValue());

       lookupValue[0].entityType = "Contact";

       window.top.opener.Xrm.Page.data.entity.attributes.get("customerid").setValue(lookupValue);

               window.top.opener.Xrm.Page.data.entity.attributes.get("name").setValue(Xrm.Page.data.entity.attributes.get("firstname").getValue());

  • Gennaro Profile Picture
    on at

    Hi Goutam,

    thanks for your reply on my problem :)

    Unfortunately the object window.top.opener.Xrm is null and on my page there is no Xrm object because is a pure HTML page which calls the CRM using the WebAPI.

    Nevertheless I can confirm that:

    window.opener.parent.Xrm.Page.getAttribute("title").getValue()

    get me the value of a text field (in this case "am 16.02.2018")

    and this

    window.opener.parent.Xrm.Page.getAttribute("title").setValue("my value")

    changes instantly the title of the case.

    if I do this:

    window.parent.opener.parent.Xrm.Page.getAttribute("customerid").getValue()

    I get null (and can be OK because the Incident is new)

    but after the .setValue on the "customerid" which is a lookup and I put an object created as you suggested, the following .getValue() continue to return null :(

    As one more info: if I set the "customerid" with this:

    window.parent.opener.parent.Xrm.Page.getAttribute("customerid").getValue()

    I get the value, but the .setValue continue to not work.

  • Suggested answer
    Ruben Raposo Profile Picture
    60 on at

    Hi Genaro,

    I don't know if you have been able to solve your challenge, but i found a way to update the lookup or another field from the children window to the parent.

    Please check the piece of code below:

    function SetEmailFrom() {
        
        var object = new Array();
        object[0] = new Object();
        object[0].id = "the id";
        object[0].name = "the name";
        object[0].entityType = "contact";
        
        window.top.opener.frames[0].Xrm.Page.getAttribute("to").setValue(object);
    }



  • Gennaro Profile Picture
    on at

    Hi there,

    thanks for the suggestion: at the end I can't tell you what the problem was but it worked ... maybe a misspell :)

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