function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ClintHegneyClintHegney 

Issue using JScript vs VBScript with the Office Toolkit library

I have the following code files; one version in VBScript and the other in JScript.
 
Code:
'*
'*
'* Script Name: test.vbs
'* Description: Sample Salesforce Script using VBScript technology
'* Created On : Thursday, August 2nd, 2007
'* Created By : Clinton Hegney <c_hegney@gelco.com>
'*
'*


'---------------------------< VARABLE DECLARATION >----------------------------

dim SforceSession, loginResult, userName, password



'---------------------------< CONSTANT DECLARATION >---------------------------





'-------------------------------< MAIN PROGRAM >-------------------------------

If Not WScript.Arguments.Named.Exists("usr") Or Len(WScript.Arguments.Named("usr")) = 0 Then
    WScript.StdOut.Write vbCrLf & vbCrLf & "A username was not given." & vbCrLf & vbCrLf
    WScript.Quit
Else
    userName = WScript.Arguments.Named("usr")
End If

If Not WScript.Arguments.Named.Exists("usr") Or Len(WScript.Arguments.Named("usr")) = 0 Then
    WScript.StdOut.Write vbCrLf & vbCrLf & "A password was not given." & vbCrLf & vbCrLf
    WScript.Quit
Else
    password = WScript.Arguments.Named("pwd")
End If

WScript.StdOut.Write vbCrLf & vbCrLf & "Username:" & + userName
WScript.StdOut.Write vbCrLf & "Password: " & password

' Create the Sforce session object.
Set SforceSession = WScript.CreateObject( "SForceOfficeToolkit3.SForceSession3.1" )

' Login to Salesforce storing the result and print the result to the screen.
loginResult = SforceSession.login( userName, password )
WScript.StdOut.Write vbCrLf & vbCrLf & "Successful login— " & loginResult & vbCrLf & vbCrLf

dim qr, ids(1)

ids(0) = "0033000000B5tEq"
Set qr = SforceSession.Retrieve("*", "contact", ids, False)

WScript.StdOut.Write qr.EntityType & vbCrLf
WScript.StdOut.Write qr.Size & vbCrLf & vbCrLf

For Each so In qr

    WScript.StdOut.Write so.ObjectType & vbCrLf & vbCrLf

Next

 
Code:
/*
 *
 * Script Name: test.js
 * Description: Sample Salesforce Script using JScript technology
 * Created On : Friday, June 13th, 2007
 * Created By : Clinton Hegney <c_hegney@gelco.com>
 *
 */


//--------------------------< VARABLE DECLARATION >----------------------------

var SforceSession, loginResult

var userName = WScript.Arguments.Named("usr");
var password = WScript.Arguments.Named("pwd");


//--------------------------< CONSTANT DECLARATION >---------------------------





//------------------------------< MAIN PROGRAM >-------------------------------

WScript.StdOut.Write("\n\nUsername: " + userName);
WScript.StdOut.Write("\nPassword: " + password);

if ( userName == undefined || userName.length == 0 ) {
    WScript.StdOut.Write("\n\nA username was not given.\n\n");
    WScript.Quit();
}
if ( password == undefined || password.length == 0 ) {
    WScript.StdOut.Write("\n\nA password was not given.\n\n");
    WScript.Quit();
}

// Create the Sforce session object.
SforceSession = WScript.CreateObject( "SForceOfficeToolkit3.SForceSession3.1" );

// Login to Salesforce storing the result and print the result to the screen.
loginResult = SforceSession.login( userName, password );
WScript.StdOut.Write( "\n\nSuccessful login— " + loginResult + "\n\n" );

var qr = SforceSession.Retrieve("*", "contact", ("0033000000B5tEq"), false);
WScript.StdOut.Write(qr.EntityType + "\n");
WScript.StdOut.Write(qr.Size + "\n\n");
for (i = 1; i <= qr.Size; i++) {
    WScript.StdOut.Write(qr[i].ObjectType + "\n\n");
}

 
The VBScript version runs fine, but the JScript version errors out with the following error.
 
test.js(50, 5) Microsoft JScript runtime error: 'qr[...].ObjectType' is null or not an object
 
What am I missing here?
foghornfoghorn

You can’t access query results by index.

 

Try this:

 

            var q = "select * from contact"
           
var qr = sfApi.Query(q,false);

           
var e = new Enumerator(qr)

           
while (!e.atEnd())
           
{
                  alert(e
.item().ObjectType)
                  e
.moveNext()
           
}

ClintHegneyClintHegney
Thanks very much, this worked perfectly.