I have written the WSH script using JScript. I am currently getting in stuck that I cannot refer to the namespace "Microsoft.Office.Interop.Outlook.OlRuletype". The source code is shown below:
var olApp = WScript.CreateObject("Outlook.Application");
var olNS = olApp.Session;
var folder = olNS.Folders("[email protected]").Folders("Inbox");
CreateRule(olNS);
ShowInbox(folder);
function CreateRule(olNS)
{
var rules = olNS.DefaultStore.GetRules();
//Error occurred here..
//Error: 'Microsoft' is undefined
//Code: 800A1391
//Source: Microsoft JScript runtime error
var opt = Microsoft.Office.Interop.Outlook.OlRuletype.olRuleReceive;
var newRule = rules.Create("Testing", opt);
}
function ShowInbox(folder)
{
if (olApp.Explorers.Count == 0)
{
folder.Display();
}
}
Am I correctly referring to the namespace? Thank you for every suggestion in advance.
Windows Script Host and JScript don't know anything about constants in type library enumerations. You need to explicitly define these constants in your script:
var olRuleReceive = 0;
var olRuleSend = 1;
So, have I need to find out about the number of constant value myself? Do you have some way to search that value from MSDN document?
You have several options:
Look up the constant values in the Outlook developer reference in MSDN.
Look up the constant values in the VBA Object Browser (see Bill_Stewart's comment).
Place your code into a Windows Script File (.wsf) and import the Outlook type library using the <reference> element. In this case you can use all Outlook enumeration constants without having to declare them.
<job>
<reference object="Outlook.Application"/>
<script language="JScript">
WScript.Echo(olRuleSend); // 1
</script>
</job>