Microsoft CRM 4.0 - Invoice Lookup

I am creating a lookup to the Invoice entity using an N:1 relationship.  This works but I want to populate the lookup with the Invoice ID (the number), not the Name that is returned to my lookup.

Can someone tell me how to get the invoice number to populate the lookup?

Thanks
LVL 1
apollo7Asked:
Who is Participating?
 
Chinmay PatelConnect With a Mentor Enterprise ArchitectCommented:
Hi apollo7,

Here is the script to retrieve the invoice number

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\">" + 
 GenerateAuthenticationHeader() +"  <soap:Body>" + 
"    <Retrieve xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
"      <entityName>invoice</entityName>" + 
"      <id>GUID</id>" + 
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" + 
"        <q1:Attributes>" + 
"          <q1:Attribute>invoicenumber</q1:Attribute>" + 
"        </q1:Attributes>" + 
"      </columnSet>" + 
"    </Retrieve>" + 
"  </soap:Body>" + 
"</soap:Envelope>" + 
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
alert(resultXml.xml);

Open in new window


You will have to replace GUID with the guid from your lookup and once you get the results you will have to process the XML and get the invoice number.

Let me know if you need help with that.

I've started working on a new assignment hence the delay.

Regards,
Chinmay

0
 
Chinmay PatelEnterprise ArchitectCommented:
Hi apollo7,

It won't work out of the box. What we will have to do is

 - Keep the invoice lookup as it is and it will always display the name.
 - Add another field to show the invoice number
 - Write a script on change of the invoice lookup to retrieve the invoice number and then populate invoice number field.

If you got the idea and are ok with it let me know, I will write the script.

Regards,
Chinmay
0
 
apollo7Author Commented:
That sounds good to me, i look forward to seeing the script

Thanks
0
 
smartappCommented:
Hi apollo7,

Dynamics CRM always shows the main attribute (name) on the lookup text.
The solution I suggest, is to create a new field and use it for the invoice name. And you add a Script on change of the invoice filed to copy the same value in the main attribute (not the new field).
Can write the script for you if this solution is OK.

Thanks
0
 
apollo7Author Commented:
Thanks, works well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.