Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

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

0
apollo7
Asked:
apollo7
  • 7
  • 3
1 Solution
 
Aftab_KhateebCommented:
Can you add an alert (below) after the line var resultXml = xmlHttpRequest.responseXML;  
alert(resultXml);
let me know what you get as response
Can you please add the word debugger at the top of all these lines and publish? this would help you to step each line and debug the issue proned line or area?

let me know how u go
0
 
apollo7Author Commented:
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

0
 
apollo7Author Commented:
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Aftab_KhateebCommented:
Ok let me have a look and get back to you
0
 
apollo7Author Commented:
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
0
 
Aftab_KhateebCommented:
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?
0
 
apollo7Author Commented:
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
0
 
apollo7Author Commented:
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

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

Chinmay, perhaps :)
0
 
apollo7Author Commented:
Aftab - thanks for your help with this, your comments helped me figure out the problem.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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