How do I get data of a field in an entity and populates that in another entity?
-
8 grudnia 2011 18:37
Hi,
In my Opportunity entity, I have a lookup field of contact. If I click on that contact in the field, it brings up the contact form and in there is the parent customer field. My question is how do I get that Parent Customer field(also a lookup field) to populates in a field in my Order form? Essentially, when I go to convert an opportunity to an order, I want the Parent Customer field in the contact entity to populates in Customer field in the Order form. I am fairly new to the web services and Jscript call. I am using Microsoft CRM 2011.
Please help,
- Zmodyfikowany przez SeekingKnowledge 8 grudnia 2011 18:37
Wszystkie odpowiedzi
-
8 grudnia 2011 19:20Moderator
Here is a tutorial on getting data from a lookup.
http://mileyja.blogspot.com/2011/05/how-to-get-and-set-lookup-value-in.html
Also here is an example of an update call in Jscript
http://mileyja.blogspot.com/2011/04/how-to-use-update-requests-in-net-and.html
There are many more examples for different web service calls that include jscript examples here:
http://mileyja.blogspot.com/p/microsoft-dynamics-crm-2011-sdk-index.html
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Zmodyfikowany przez Jamie MileyMVP, Moderator 8 grudnia 2011 19:22
- Zaproponowany jako odpowiedź przez Jamie MileyMVP, Moderator 8 grudnia 2011 19:22
- Oznaczony jako odpowiedź przez Jamie MileyMVP, Moderator 6 marca 2013 17:56
-
8 grudnia 2011 20:34
Hi Jamie,
Here is my code, but I am getting an jscript error of Error: "Object expected" on the Order form.
function Setcustomerfield()
{
//Get a lookup value
var lookupItem = new Array();
lookupItem = Xrm.Page.getAttribute("parentcustomerid").getValue();
if (lookupItem[0] != null)
{
var name = lookupItem[0].ParentCustomer;
var id = lookupItem[0].E84F29AD-F557-DC11-9DAE-000F20DAD965;
var entitytype = lookupItem[0].Contact;
}
{
//Set a lookup value
var value = new Array();
value[0] = new Object();
value[0].id = 40063E3E-E999-DF11-BFB1-0015600F6010;
value[0].name = Customer;
value[0].entityType = Order;
Xrm.Page.getAttribute("customerid").setValue(value);
}}
Am I missing something?
-
8 grudnia 2011 20:49Moderator
Probably, but I am not sure what. I would try debugging your jscript. It should help you see where the problem is.
http://mileyja.blogspot.com/2011/05/debugging-jscript-in-microsoft-dynamics.html
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter! -
8 grudnia 2011 20:50
When you go to the form, press the F12 key, this will bring up the IE debugger.
If you then click script, start debugging.
You can then lookup your javascript file and put in a break point, walk through the code
Ben Hosking
Check out my CRM Blog
Linked-In Profile
Follow Me on Twitter!- Oznaczony jako odpowiedź przez Jamie MileyMVP, Moderator 6 marca 2013 17:56
-
8 grudnia 2011 20:52Moderatoryup, that works too.
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter! -
8 grudnia 2011 21:55
On which entity did you write this script?
I dont think there is an attribute called parentcustomerid on order entity. The XRM code will only return attributes available on the current entity.
HTH
Sam
Web: http://www.inogic.com
Blog: http://inogic.blogspot.com
Email: news@inogic.com
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Zaproponowany jako odpowiedź przez Sam - InogicMVP 8 grudnia 2011 21:55
- Oznaczony jako odpowiedź przez Jamie MileyMVP, Moderator 6 marca 2013 17:56
-
9 grudnia 2011 00:03
Sam,
I have the Jscript on the onload in the Order form. You're right, it doesn't have parentcustomerid, do you know how I would modify that above jscript to take the lookup value from parentcustomerid (field in contact form) and populates that into the customerid field in Order form?
- Zmodyfikowany przez SeekingKnowledge 9 grudnia 2011 00:04
-
12 grudnia 2011 07:35
On the Order form, you need to have two fields the contact that will be copied over from the Opportunity and the account, where you would copy the parentcustomerid from the contact.
Next, on the onload event in the Order form, you will need to write a retrievemulitple script that would read teh contact details based on the Contact Guid available on the order. It would then get the Account asociated with the contact from the retrieve script. This will then be set as the account on the Order.
You can download the SDK for sample on scripting for retrieve multiple..
HTH
Sam
Web: http://www.inogic.com
Blog: http://inogic.blogspot.com
Email: news@inogic.com
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". -
12 grudnia 2011 20:35
This is what I have
function customeraccount(o) {
var authenticationHeader;
var serverUrl;
var orgName;
var ODataPath;//Set up defaults
var lookupItem = new Array;lookupItem = Xrm.Page.getAttribute("customerid").getValue();
if (lookupItem != null) {
var context = o.getContext();
authenticationHeader = context.getAuthenticationHeader();
serverUrl = context.getServerUrl();
orgName = context.getOrgUniqueName();
if (serverUrl.indexOf(orgName) > 0) {
serverUrl = serverUrl.substring(0, serverUrl.indexOf(orgName) - 1)
//DEV
serverUrl += ".ecri.org";
//DEV
}
ODataPath = serverUrl + "/mscrmservices/2007/CrmService.asmx"; //Prod!!!!!!!!!!
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
Xrm.Page.context.getAuthenticationHeader() +
" <soap:Body>" +
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
"<q1:EntityName>account</q1:EntityName>" +
"<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
"<q1:Attribute>name</q1:Attribute>" +
"<q1:Attribute>accountid</q1:Attribute>" +
"</q1:Attributes>" +
"</q1:ColumnSet>" +
"<q1:Distinct>false</q1:Distinct>" +
"<q1:Criteria>" +
"<q1:FilterOperator>And</q1:FilterOperator>" +
"<q1:Conditions>" +
"<q1:Condition>" +
"<q1:AttributeName>accountid</q1:AttributeName>" +
"<q1:Operator>Equal</q1:Operator>" +
"<q1:Values>" +
"<q1:Value xsi:type='xsd:string'>" + user.selectSingleNode("q1:parentcustomerid").text + "</q1:Value>" +
"</q1:Values>" +
"</q1:Condition>" +
"</q1:Conditions>" +
"</q1:Criteria>" +
"</query>" +
"</RetrieveMultiple>" +
"</soap:Body>" +
"</soap:Envelope>";// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
// Parse and display the results.
else {
var results = resultXml.getElementsByTagName('BusinessEntity');
var msg = "";
if (results.length == 0) {
msg = "No Account records were found for " + user.selectSingleNode("q1:parentcustomerid").text + ".";
alert(msg);
} //if (results.length == 0)
else {
for (j = 0; j < results.length; j++) {
var account = results[j].selectSingleNode("//BusinessEntity");var AID = account.selectSingleNode("q1:accountid").text;
var Aname = account.selectSingleNode("q1:name").text;//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
var lookupItemAID = new Object();
//Set the id, typename, and name properties to the object.
lookupItemAID.id = AID;
lookupItemAID.entityType = 'account';
lookupItemAID.name = Aname;
// Add the object to the array.
lookupData[0] = lookupItemAID;
// Set the value of the lookup field to the value of the array.
Xrm.Page.getAttribute("new_customeraccount").setValue(lookupData);
Xrm.Page.getAttribute("new_customeraccount").setSubmitMode("always");if (account.selectSingleNode("q1:name") != null) {
Xrm.Page.getAttribute("new_customeraccount").setValue(account.selectSingleNode("q1:name").text);
Xrm.Page.getAttribute("new_customeraccount").setSubmitMode("always");
}
}
}
}} // if (user.selectSingleNode("q1:parentcustomerid") != null)
} // for (i = 0; i < results.length; i++)
} // else if (results.length == 0)
}} //if (lookupItem != null)
} //End function new_billtocontactid_onchangeI am getting objected expected error, any clue what is wrong with my Jscript?
- Zmodyfikowany przez SeekingKnowledge 12 grudnia 2011 20:36
-
12 grudnia 2011 21:26Moderator
Two things:
1. Is there a reason you are using the old CRM 4.0 service that is left there for backward compatibility for new development? The next version of may very well not include this service. I recommend programming against the 2011 organization service.
2. Did you try that debugging technique Hosk and I pointed out? It will tell you the exact line that has your error and you can see what object is probably coming up null and then you can deduce why.
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter! -
1 kwietnia 2012 20:05ModeratorDid you find the answer to your question?
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter! -
21 marca 2013 07:13
Hi,
please follow this links;
http://mileyja.blogspot.com/2011/05/how-to-get-and-set-lookup-value-in.html
http://mileyja.blogspot.com/2011/04/how-to-use-update-requests-in-net-and.htmlhttp://mileyja.blogspot.com/p/microsoft-dynamics-crm-2011-sdk-index.html
Please vote if this is useful to you.
thankyou