Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript in Cognos - won't run <CreateNewsItem> - I need some help

Status
Not open for further replies.

Annabel

Programmer
Jul 14, 2003
6
AU
I hope someone can help me.

I have a piece of VBScript code which works on 2 colleague's machines but will not work on mine.

At first we thought it might be because I didn't have Cognos installed on my machine but even after installing Cognos, the script still doesn't work.

Here's the script (basically changed from one of the samples supplied in Cognos). Please ignore the links...They are not meant to be links, just examples of code and/or messages returned. (I don't know how to turn the links off.....my first post)



'*Requirements:
'* 1). install WScript host engine first.
'* 2). Automation Client requires only two dlls: UpfAuto.dll, UpfrontConnectv3.dll.
'*

' Global Variable:
Dim g_FileSysObj

'Create the File Object to output the result:
Set g_FileSysObj = CreateObject("Scripting.FileSystemObject")

UpfAutomation


'********************************************************************************
'* Input: - none
'*
'* Output: - successful publishing of a news item to one newsbox.
'*
'* Description: Publish a file called test.pdf in someone's newsbox
'*
'********************************************************************************
Sub UpfAutomation()

Dim UpfSession, UpfCheck
Dim logonUpf, logoffUpf, serverClick, userClick
Dim xmlNewsBox, xmlNewsItem, NewsBoxID, NewNB

MsgBox "This script will publish a file called test.pdf in someone's newsbox"


'Create Upfront session object:
Set Upfsession = CreateObject("Upfront.UpfrontSession")
logonUpf = Upfsession.Login("myservername", "myuser", "password", "Root User Class")

'Run a describe system command so you can extract out the BaseNewsBoxId,write the result to a file via printmsg and then check the outcome
NewsBoxID = Upfsession.XMLCmd(&quot;<DescribeSystem RequestId='System'></DescribeSystem>&quot;)

PrintMsg (NewsBoxID)



'Check if the Upfront Session is Initialized
UpfCheck = CheckSession

If UpfCheck = &quot;Fail&quot; then
MsgBox &quot;The Upfront Session is not intialized&quot;
Exit Sub
End if

'extract the id value from the file and assign it to a variable for use later
NewNB = &quot;mynewsboxid&quot;

'Create a newsitem inside the newsbox that you want
xmlNewsItem = Upfsession.XMLCmd(&quot;<CreateNewsItem><Name>Test%20file</Name><ParentId>&quot; + NewNB + &quot;</ParentId><ProviderType>Other</ProviderType><DefaultAction>View</DefaultAction><Action><Name>View</Name><URLText>
printmsg(xmlnewsitem)

'log out of Upfront session
logoffUpf = Upfsession.logout()

MsgBox &quot;Logon to Upfront and Select the NewsBox to see the Results&quot;

End Sub


'********************************************************************************
'* Input: - Message: The message to print to a file.
'*
'* Output: - none.
'*
'* Description: This function prints strings to a file
'*
'********************************************************************************
Sub PrintMsg(Message)

Dim fFile, rc

rc = g_FileSysObj.FileExists(&quot;C:\xmlresultVBS.txt&quot;)

If rc Then
g_FileSysObj.DeleteFile(&quot;C:\xmlresultVBS.txt&quot;)
End If

Set fFile = g_FileSysObj.OpenTextFile(&quot;C:\xmlresultVBS.txt&quot;, 8, 1) 'OverWrite
fFile.WriteLine (Message)
fFile.WriteLine (vbCrLf)
fFile.Close

End Sub


'********************************************************************************
'* Input: - none:
'*
'* Output: - error
'*
'* Description: This function check to see if the Upfront session initialized
'*
'********************************************************************************

Function CheckSession()

Dim fileToRead, strInput, oneBigString
Dim pos1, pos2, myId

set fileToRead = g_FileSysObj.OpenTextFile(&quot;C:\xmlresultvbs.txt&quot;, 1)
oneBigString = fileToRead.ReadAll

pos1 = InStr(1, oneBigString, &quot;ResultCode=&quot;, 1)
pos2 = InStr(1, oneBigString, &quot;<Message>&quot;, 1)
if pos2 = 0 then
CheckSession = &quot;Success&quot;
Exit Function
End if

myId = Mid(oneBigString, pos1 + 12, pos2 - 2 - pos1 - 12)


CheckSession = myId

End Function

It all works except for the createnewsitem XML command.

I get the following message back when I run it :-

<?xml version=&quot;1.0&quot; encoding=&quot;windows-1252&quot; standalone=&quot;yes&quot;?><Result xmlns=&quot; ResultCode=&quot;Fail&quot;><Message>The object of type (NewsItem) cannot be created because it references a non-existing object.
</Message></Standard_Result></Result>.


When it runs properly (ie on a colleague's machine) we get a different message suggesting a resultcode = &quot;success&quot; and a newsitem id which gets created.

I hope this is clear enough for someone to understand (and to help me.....maybe??)

thanks in advance
 
There is something wrong with the <parent ID> value on your machine. Check the value that the variable is populated with on your machine, and compare to a working machine value. Something is making the difference on your machine, could be the VB version or OS version or service pack. With this much info, just compare them and then try and see where the difference comes from. Good luck!
 
Waspy,

Thanks for the response I didn't expect one until tomorrow morning at least..heaven knows why I'm still in the office....I should be reading this tomorrow morning and not now.

Anyway, since you have responded, I have a further question.

Unless I have completly misunderstood XML, the ParentId value I give the command is the value of NewNB. (Yes??)

If this is the case, I have this value hardcoded (for testing). So, when one of my colleagues runs the script, the value of NewNB is exactly the same as when run on my machine. ie the copy of the VBS is the same.


Is there another <ParentId> value I should be looking for?

[blush]I don't know Cognos well, nor XML....or VBS for that matter....I just get by learning as I go.

thanks again
AP
 
You are correct - the parent id is what is found in the Upfront - newsbox/properties - newsbox ID. So, if you have hardcoded this, it makes no sense that it works on one machine, but not another. All you are really doing is sending the XML command via the URL - you could test just that line in a browser interactively to see if it errors with more information? Maybe you have a different version or security setup of the browser?
 
OK thanks for that.

That is what we thought here as well. At least I hadn't misunderstood something.

Just while we're on the subject, was I also correct in believing that I didn't need Cognos installed on my machine just upfauto.dll and upfrontconnectv3.dll?

I'll let you know what happens with my machine.

thanks again
AP
 
Hi Waspy,

I tried as you said and pasted in the xmlcommand straight into my browser and it worked.

Is there a way I can see the actual browser command that is about to be executed rather than only seeing the outcome?

Maybe nearly there....

AP
 
Try not issuing the command, but simply print it to screen?
 
Waspy,

Good grief....still here but going home now.

so far I have the following (from my machine)


<SuperUserACL><ACL type=&quot;List&quot;><UserClass name=&quot;Root User Class&quot;/><UserClass na
me=&quot;mycompany Cognos Administrators&quot;/></ACL></SuperUserACL><AdminACL><ACL type=&quot;List&quot;><UserClass name=&quot;Root User Class&quot;/><UserClass name=&quot;mycompany Cognos Administrators&quot;/></ACL></AdminACL><Version>7.1 Build 151 Rev 29

which is different to (from colleague's machine)


<SuperUserACL><ACL type=&quot;List&quot;><UserClass name=&quot;Root User Class&quot;/></ACL></SuperUserACL><AdminACL><ACL type=&quot;List&quot;><UserClass name=&quot;Root User Class&quot;/></ACL></AdminACL><Version>7.1 Build 151 Rev 29

This is obtained from the result of the &quot;describe system&quot; command.

It also shows me that the base newsboxid (newsindex) is different on each machine

Also, BaseNewsBoxRawName is &quot;NewsIndex&quot; on my colleagues machine but it is &quot;_default_index_name_&quot; on my machine.

I'll ask my Cognos colleague tomorrow to see if he can find some kind of security/logon/authentication differences between machines. Yuk...it's getting v ugly.[dazed] ....stay tuned!!

AP
 
Well, good luck, but if the base newsbox IDs are different, you are hitting another version of Upfront somehow. Have fun in the sun, and keep us updated =)
 
Hello again,

Here is the latest update on this. The good news is that it is working.

Now for the why and how.....


We have a development environment and a production environment. Each is specified by using the appropriate server IP address in the HOSTS file. We have a 2 .bat files (1 production and 1 development) and we run whichever .bat file is needed depending on which server we want to point to. The .bat file basically generates a new HOSTS file containing the correct IP addresses for several servers.

So, having determined I was pointing to the wrong server I ran the producton.bat file....but alas no good.

The .bat files write the HOSTS file to c:\winnt\system32\drivers\etc but I am on XP which uses c:\windows...

So, placed the correct HOSTS file in c:\windows\system32\drivers\etc and it WORKS!!!


thanks for the help Waspy....nice to know I had someone out there who was listening.[thumbsup]
 
My pleasure - glad its all working now. Have a great weekend.
James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top