Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 822
  • Last Modified:

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
0
apollo7
Asked:
apollo7
  • 2
  • 2
1 Solution
 
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
 
Chinmay PatelEnterprise 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
 
apollo7Author Commented:
Thanks, works well.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now