Rob
Rob

Reputation: 531

How do I pull data from regarded entity in CRM 2011

I hope someone can assist.

I am new to CRM javascript development. I am trying to pull a field of data from a regarded (account or case) within an email. What I would like to do, is when a new email is created I would like the javascript to read the regarded account or case for a field that will tell the javascript to change the from address of the outgoing email.

I tried to get it to work but I am finding it hard to find exactly what I am looking for within the MS documentation. I'm not sure if parent is what I am supposed to be using or not. I would have figured that "regarding" would have been the word used but I am now at my limit of understanding. I assume that parent means anything that is regarded?

I know that I'm a noob but any help would be appreciated.

function Form_Onload(){
    changeFromAddress()
}

function changeFromAddress(){

    var parentAccount = window.parent.opener.Xrm.Page.data.entity.attributes.get("FFFAccountType").getValue();

    if (parentAccount == "CorpAccount"){

        Xrm.Page.getAttribute(“From”).setValue(‘[email protected]’);
    }
}

Upvotes: 1

Views: 426

Answers (1)

James Wood
James Wood

Reputation: 17562

You can only use the Xrm.Page functions to update the values on the current record (on the window you have open). If you want to update a related record you will need to perform a web service call.

I would suggest having a read of Getting started with CRM 2011 JavaScript REST (OData) Web Service Calls.

Its from my blog but it describes how to get going with web service calls which you can use to update the related record.

As a side point, for this type of behavior I would be using a workflow, its much easier to implement in the short term and maintain in the long term. What benefit do you by performing the updated in JavaScript?

window.parent doesn't really apply in this situation that's for accessing the physical browser window, it wont help you to navigate CRM data.

Upvotes: 1

Related Questions