Link to home
Start Free TrialLog in
Avatar of apollo7
apollo7Flag for United States of America

asked on

XML Help

I created a price level lookup on the Lead form.  I want to populate it with the price level of the current logged in user.  I have included below some xml that I have used to populate other fields on other forms but it is not working for pricelevel on the Leads.

It is in the onLoad event and does not populate the pricelevel field at all.

Thanks
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>" +   
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +   
"      <Request xsi:type=\"WhoAmIRequest\" />" +   
"    </Execute>" +   
"  </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/Execute");  
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");  
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);  
xmlHttpRequest.send(xml);  
  
var resultXml = xmlHttpRequest.responseXML;  
  
var userId = resultXml.selectSingleNode("//UserId").text;  
  
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>systemuser</entityName>" +   
"      <id>"+ userId + "</id>" +   
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" +   
"        <q1:Attributes>" +   
"          <q1:Attribute>pricelevelid</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;  
  
crmForm.all.new_pricelistid.DataValue = resultXml.selectSingleNode("//q1:pricelevelid").text;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aftab_Khateeb
Aftab_Khateeb
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of apollo7

ASKER

I will setup and run your suggestion above.  I have some additional information, however, that might help.  This xml code has been used to bring in various fields associated with the logged in user (firstname, lastname, domainname) without error.  

I have taken this xml from the onload event on the Lead form and made some slight modifications to populuate the firstname of logged in user in an nvarchar field (as opposed to a lookup field) called new_currentuser.  When I open the Lead form now, the new current user is populated with the logged in user's firstname.  The code that does this is below.

I will add the alert as you suggested and report the results.  However, I felt that the code working as presented below may also give you some clues as to what the problem is..

Thanks


It is in the onLoad event and does not populate the pricelevel field at all.


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>" +   
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +   
"      <Request xsi:type=\"WhoAmIRequest\" />" +   
"    </Execute>" +   
"  </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/Execute");  
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");  
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);  
xmlHttpRequest.send(xml);  
  
var resultXml = xmlHttpRequest.responseXML;  
  
var userId = resultXml.selectSingleNode("//UserId").text;  
  
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>systemuser</entityName>" +   
"      <id>"+ userId + "</id>" +   
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" +   
"        <q1:Attributes>" +   
"          <q1:Attribute>firstname</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;  
  
crmForm.all.new_currentuser.DataValue = resultXml.selectSingleNode("//q1:firstname").text;

Open in new window

Avatar of apollo7

ASKER

Note:ignore the last line above "It is in the onLoad event and does not populate the pricelevel field at all"
It must have gotten copied from the earlier entry.

Also, the only changes I made to the xml to populate the new_currentuser field on Lead are lines 33 and 51:

33: <q1:Attribute>firstname</q1:Attribute>" +    
51: crmForm.all.new_currentuser.DataValue = resultXml.selectSingleNode("//q1:firstname").text;

The remaining xml is the same.

Thanks
Ok let me have a look and get back to you
Avatar of apollo7

ASKER

Thanks, ran the alert you suggested and the results are below:

For alert(resultxml.xml) with firstname in the onload event, I receive the following:

xmlns:q1="http://schemas.microsoft.com/crm/2007/WebServices"
xsi:type="q1:systemuser"><q1:firstname>ADMIN</q1:firstname>
<q1:systemuserid>{68D9127F-2B73-DF77-D58D-15066906507}<q1:systemuserid>
<q1:businessunitid>{2567ACFB-2B73-DF77-D58D-15066906507}</q1:businessunitid>
<RetrieveResult>
<RetrieveResponse>

No error and firstname populates the field on the form.

=================================================================

If I change line 33 and line 51 to pricelevelid, I get the attached error.  Based on the error, I looked under the systemuser entity and saw there is no pricelevelid (as indicated in the alert).  The pricelevelid guid appears to be in the pricelevel entity and the pricelevelidname appears to be in productpricelevel.

What it appears I need is for my field - new_pricelistid - to be populated, onload, by the pricelevelidname. Not sure how to do this, thanks for your help.


xml-systemuser.jpg
Yes the pricelevelid does not exists on systemuser entity. May I know what is the purpose of fetching pricelevel which is at product level and relating it to the user and particularly the logged in user?
Avatar of apollo7

ASKER

Sure, I will tell you what I know.  First, the price lists are setup by location so whoever is logged in will be selling for their location.  For example if Joe from New York City is logged in, he is selling for the NYC sales office (pricelevel = NYC)

Second, the entire order process has been setup this way. So regardless of where you enter the process (opportunity, quote, order, invoice), the logged in user's related price list is automatically populated in the order or quote or whatever they are entering.  Through relationships/mappings, the price level then follows the order from opportunity to invoice.

Currently, the pricelevel I have added to Leads flows to Opportunities (through a mapping) but you need to manually select the price list in the Lead form.  Sales management want it auto-selected based on whoever is logged in (as it already does in opportunity, quote, order and invoice).

Thanks
Avatar of apollo7

ASKER

quomodo: thanks for your efforts to get this question answered.  Since my original post, I have simplified the problem to clarify what my issue is.  I have posted that below:

My issue is: how do I populate a lookup field on the Leads form using xml in the onLoad event of the form?

The lookup field I want to populate is a custom field I added (new_pricelist) by creating a relationship between Leads and Price Level.  What I am doing with the xml below is 1) capture the domainname and businessunitname of the current logged in user and 2) write this to 2 fields: new_currentuser (text field) and new_pricelist (lookup field).

To test the xml, I added another text field - new_pricelevel - to the form. Everything works fine if I write to the text fields:

crmForm.all.new_currentuser.DataValue = domainName;
crmForm.all.new_pricelevel.DataValue = businessUnitName;

If I change the last two lines of the xml to use the lookup field, then I get an error:

crmForm.all.new_currentuser.DataValue = domainName;
crmForm.all.new_pricelist.DataValue = businessUnitName;

The full xml is attached below.  Thanks
 
var xml;
    var resultXml;
    var userId;
    var domainName;
    var businessUnitName;
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    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>" +
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"      <Request xsi:type=\"WhoAmIRequest\" />" +
"    </Execute>" +
"  </soap:Body>" +
"</soap:Envelope>" +
"";

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

    resultXml = xmlHttpRequest.responseXML;
    userId = resultXml.selectSingleNode("//UserId").text;
    
    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>systemuser</entityName>" +
"      <id>" + userId + "</id>" +
"      <columnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" +
"        <q1:Attributes>" +
"          <q1:Attribute>domainname</q1:Attribute>" +
"          <q1:Attribute>businessunitid</q1:Attribute>" +
"        </q1:Attributes>" +
"      </columnSet>" +
"    </Retrieve>" +
"  </soap:Body>" +
"</soap:Envelope>" +
"";

    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);

    resultXml = xmlHttpRequest.responseXML;
    domainName = resultXml.selectSingleNode("//q1:domainname").text; 
    businessUnitName = resultXml.selectSingleNode("//q1:businessunitid").attributes[1].text;

    crmForm.all.new_currentuser.DataValue = domainName;
    crmForm.all.new_pricelevel.DataValue = businessUnitName;

Open in new window

Avatar of apollo7

ASKER

We seem to have come to a stopping point - can some help me finish this XML?

Chinmay, perhaps :)
Avatar of apollo7

ASKER

Aftab - thanks for your help with this, your comments helped me figure out the problem.