Accessing SalesForce.com using Web Services and Scripting SOAP – Part 2

March 23, 2016

 

Powershell – SalesForce.com – SOAP Example :

CLS

# WSDL is created from within SF.Com Application
$Path = Split-Path -Path $($global:MyInvocation.MyCommand.Path)
$Uri = $Path+"\Enterprise.wsdl" # You can also chose to create a Partner WSDL


$Cred = Get-Credential –credential “<a href="mailto:“Email.LastName@company.com&quot;$SecToken">Email.LastName@company.com”
$SecToken</a> = "YOUR SECURITY TOKEN HERE"

$User = $Cred.UserName
$Password = $Cred.GetNetworkCredential().Password 

# Proxy
$service = New-WebServiceProxy -Uri $Uri -Namespace sforce -UseDefaultCredential

# Login
$loginResult = $service.login($Cred.UserName, $Password+$SecToken)

# Debug info
# $loginResult

$service = New-Object sforce.SforceService
$service.Url = $loginResult.serverUrl
$service.SessionHeaderValue = New-Object sforce.SessionHeader
$service.SessionHeaderValue.sessionId = $loginResult.sessionId

# Listing SalesForce Objects
$accountObjects = $service.describeGlobal()

Write-Host "Enum SalesForce Objects"
Write-Host "-----------------------"

Foreach ($item in $accountObjects.sobjects)
{
    Write-host ($item.name, $item.label)
}

Write-Host ""
Write-Host "Retrieving Object Meta Data"
Write-Host "---------------------------"

# Retrieving meta data about a specific object
$opportunityObject = $service.describeSObject("Opportunity")

foreach ($item in $opportunityObject.fields)
{
    Write-Host ($item.name, $item.label, $item.type)
}

Write-Host ""
Write-Host "RelationshipNames"
Write-Host "-----------------"

foreach ($item in $opportunityObject.childRelationships)
{
  Write-Host ($item.relationshipName)
}

Write-Host ""
Write-Host "Querying Objects"
Write-Host "----------"

# $StrQuery = "SELECT Id, Name, StageName, Amount FROM Opportunity WHERE IsWon = True";

$StrQuery = "SELECT AccountId, OwnerId, Name, Description, StageName, `
Amount, Probability FROM Opportunity";
 
$queryResult = $service.query($StrQuery) 
 
foreach ($item in $queryResult.records)
{
   Write-Host ( $item.AccountId, $item.OwnerId, $item.Name, ´
   $item.Description, $item.StageName, $item.Amount, $item.Probability)
}

rv Password, SecToken 

This Script will list SalesForce Account Objects.

image

Retrieves meta data about a specific object.

image

Retrieves RelationshipNames.

image

Querying Objects

image

For more info on how to get started see here

Enjoy!

Smile


SharePoint – Using JQuery & SPServices

January 24, 2015

If you are developing SharePoint you just can’t get around JQuery and the marvelous SPServices. Especially if you are dealing with SharePoint Web Services.

There are many hits on the internet if you type in these 2 keywords. But nevertheless there are very few post explaining you how to and which approach and tools can help you in your project.

Let’s say you you want to retrieve some Document ID’s & Names from documents linked into a list Form Body Text.


$(document).ready(function(){

$.fn.SPServices({
    operation: "GetListItems",
    async: false,
    webURL: "/webs/sitecollection/site",
    listName: "YourListName",
    CAMLViewFields: "",
    CAMLQuery: "1503",
    completefunc: function (xData, Status) {

    // Debug
    //alert(xData.responseText);

var liHtml = ""
      $(xData.responseXML).SPFilterNode("z:row").each(function() {

      //  $("#tasksUL").text(xData.responseText); // Debug info 

      liHtml =  "</pre>
<ul>
	<li>" + $(this).attr("ows_FileLeafRef") + "</li>
</ul>
<pre>
";
         $("#tasksUL").append(liHtml);
      });
    }
 });

});</pre>
<ul id="tasksUL"></ul>
<pre>

The code above will do so. But the mystery is which is the ows_xxx XML attributes you are looking for to get the File Name appearing in your Form.

Solution :

Uncomment this section in the code :

$(“#tasksUL”).text(xData.responseText);

And comment this line :

// liHtml =  “<li>” + $(this).attr(“ows_FileLeafRef”) + “</li><br/>”;

This will retrieve the bare output of the return SOAP Envelope in your form.

image

You can select it out of your Form, and paste it in for example XML Notepad.

image

It’s got some millage but still going strong. Smile

image

Here you can see all the Nodes and Attributes in the tree structure.

The one we are interested in is the attribute ows_FileLeafRef in the node z:row

That’s where the document ID and Name appears in.

image

Once we use that in our code, the result is looking good.

I got the 2 document references from a Document Library somewhere else in SharePoint using SP Web Services !

image

Hopefully this can clear some mist on how to get all the missing mystery information and parameters correct.


SharePoint – Web Services Data integration (SOAP)

August 27, 2014

In my previous post I explained you how to consume a Web Service using Autoit and Powershell.

Now we can see how to access the data in SharePoint.

First we need to connect to the Web Service Provider.

1. Open SP Designer and go to Data Sources. And add a new SOAP Service Connection.

image

Fill in the Web Service URL http://www.webservicex.net/uszip.asmx?WSDL

image

2. Next create a new Web Part Page

First go to Site Pages and create a new page 

image

Let’t go for a Web Part Page

image

3. Open it to insert the new SOAP Connection.

image

Once the page is open.

4. Go the Insert menu and Data View option

image

And browse down to the new connection in this case USZip Web Service.

image

5. Insert the connection in the Web Part Zone

image

6. Save it and look at the result.

image

That’s it as simple as that Winking smile

image

No let’s see that we can filter it based on a Query String.

Open the Page you created again in FD, and create :

image

1. First create a Parameter first called “CITY”  and a Query String variable called “CITY”.

image

Default value is an option.

2. Next create a Filter.

Open the Data Source Again and remove the Default value “New York” again

image

Click on the FILTER menu item

image

it should look like this in the end.

image

Save the page and test it using the Query string Parameter “City”

/sites/sandbox/SitePages/Zip%20Soap%20Test.aspx?City=New York

Enjoy !