Grabbing Serverside Information using a SOAP Webservice call (AJAX)

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Grabbing Serverside Information using a SOAP Webservice call (AJAX)

  • Comments 2
  • Likes

Please note that this is only a part worked solution.  I have added this to show how an web service request can be made from a client to extract any information (available to web services) that is needed from the server.

This example is based on code that is discussed within the Developer training.

There are two functions used in the code below.  

GetKeyValue(querystringname)

See the article:  Another Trick for Grabbing Key Values in Client Side code.

RunDemoWebServiceRequest()

This function contains the web service request.  The hard thing about using webservices from the browser is that you need to know how to construct the SOAP message and then you will need to think about how to parse the returned XML.  

That has to be for another article.

To use the code add the script to the custom content of the CompanyBoxLong screen and add "RunDemoWebServiceRequest()" to the onChange field level script for the comp_name field.  When the company name is changed a web service request is made that returns the name of the company held in the database.


<script>
function GetKeyValue(querystringname)
{
var strPath = window.location.search.substring(1);
var arrayKeys = strPath.split("&");
for (var i=0;i<arrayKeys.length;i++)
{
var arrayValue = arrayKeys[i].split("=");
if (arrayValue[0].toLowerCase()== querystringname.toLowerCase())
{
return arrayValue[1];
}
}
return "";
}
 
function RunDemoWebServiceRequest()
{
var strSID = GetKeyValue("SID");
var strKey1 = GetKeyValue("key1");
 
xmlHttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp!=null)
{
var strPath = document.URL;
var arrayApp = strPath.split("eware.dll");
var strSOAPpath = arrayApp[0]+"eware.dll/WebServices/SOAP";
var strXML = '<?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"><soap:Header><SessionHeader xmlns="http://tempuri.org/type"><sessionId>'+strSID+'</sessionId></SessionHeader></soap:Header><soap:Body><queryrecord xmlns="http://tempuri.org/type"><fieldlist>comp_companyid, comp_name</fieldlist><queryString>comp_companyid='+strKey1+'</queryString><entityname>company</entityname><orderby>comp_name</orderby></queryrecord></soap:Body></soap:Envelope>'
xmlDoc=strXML;
xmlHttp.open("POST", strSOAPpath, false);
xmlHttp.send(xmlDoc);
alert(xmlHttp.responseText);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
</script>

Comments
  • please reply soon how can i this type of query in SOAP.

    select comp_companyid,comp_name,rtrim(Phon_AreaCode)+rtrim(Phon_CountryCode)+Phon_Number from company

    join PhoneLink on PLink_EntityID = 5 and PLink_RecordID = comp_companyid

    join Phone on Phone.Phon_PhoneId = PhoneLink.PLink_PhoneId

    where Phon_Number = '720-1500'

    select phon_phoneid ,Phon_Number from Phone

  • Hello

    Have a look at this article.  community.sagecrm.com/.../finding-person-records-by-email-address-using-soap-web-services-in-sage-crm-7-2.aspx

    This covers searching for Person records by email but is very similar to searching for Company records by phone number.

    If you are using Sage CRM 7.2 then you make also want to consider using the crm.sdata method

    var companyID = crm.fields("case_primarycompanyid").value();

    var successFunction = function (crmRecord) {

       crm.infoMessage(crmRecord.comp_name);

    }

    crm.sdata(

    {

       entity: "company",

       id: companyID,

       success: successFunction

    });