Solved

XML Help

Posted on 2010-08-27
14
720 Views
Last Modified: 2013-11-18
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
Comment
Question by:apollo7
  • 7
  • 3
14 Comments
 
LVL 8

Accepted Solution

by:
Aftab_Khateeb earned 500 total points
ID: 33555751
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
 
LVL 1

Author Comment

by:apollo7
ID: 33559458
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
 
LVL 1

Author Comment

by:apollo7
ID: 33559580
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
 
LVL 8

Expert Comment

by:Aftab_Khateeb
ID: 33563221
Ok let me have a look and get back to you
0
 
LVL 1

Author Comment

by:apollo7
ID: 33563851
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 8

Expert Comment

by:Aftab_Khateeb
ID: 33583635
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
 
LVL 1

Author Comment

by:apollo7
ID: 33583928
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
 
LVL 1

Author Comment

by:apollo7
ID: 33699679
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
 
LVL 1

Author Comment

by:apollo7
ID: 33844317
We seem to have come to a stopping point - can some help me finish this XML?

Chinmay, perhaps :)
0
 
LVL 1

Author Closing Comment

by:apollo7
ID: 34010925
Aftab - thanks for your help with this, your comments helped me figure out the problem.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to count occurrences of each item in an array.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now