The AddViaTemplate command launches the FileNet Workplace Add Via Template Wizard, which enables a user to add a specified file on their local machine to an object store using the settings in an existing entry template to configure the item. The client application must use the IAddViaTemplateCmd interface to specify the item to add, and obtain the user selected entry template to apply to the added item using the SelectEntryTemplate command. Once the user has completed the add operation, an IObjectStoreItem interface is returned which may be queried to obtain a pointer to the added item. The client is responsible for deleting the local file, if desired.
After the AddViaTemplate command has been executed by calling IAppIntCmd::Invoke, an AddViaTemplate response component is returned. Client applications may interact with the Response component via the standard IAppIntRsp and custom IAddViaTemplateRsp interfaces. For more information about working with command and response components and their COM interfaces, see Command and Response components.
DLL | FnAppIntAddViaTemplateCmd.dll |
See Also | Add and SelectEntryTemplate commands |
The AddViaTemplate command uses the following interfaces:
Interface | Description |
---|---|
IAddViaTemplateCmd |
This is a custom interface used to initialize the data contained in the AddViaTemplate command component. The client application can use the methods in this interface to customize the dialog title, identify the item to add, use the entry template selected by the user, define XML properties for the added item, and specify the link relationship to establish between the added item and other items already in the object store. When Records Manager is enabled for the Application Engine, this method can also be used to specify whether the Declare Record operation should be made available for the specified object store. |
IAddViaTemplateRsp |
This is a custom interface for the AddViaTemplate response component that is returned when the AddViaTemplate command is executed. This interface enables the client application to obtain information about the item that was added to the object store. |
IAppIntCmd |
This is a standard interface which is automatically used by the AddViaTemplate command to invoke the AddViaTemplate command component. The client application executes the AddViaTemplate command by calling this interface and passing the AppIntSession component on which the AddViaTemplate command component is invoked. Each time the command is executed, an AddViaTemplate response component is returned. |
IAppIntRsp |
This is a standard interface that is automatically used by the AddViaTemplate command to determine the success or failure of the command, as well as retrieve any error code or messages. |
In the application's StdAfx.h header file:
#import"C:\Program Files\FileNet\AppInt\FnAppIntCmd.tlb" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntHttpRequest.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntBrowserDlg.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntHttpConnection.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntResources.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntClientRecordBase.tlb" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntClientStore.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntSession.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntSessionLogin.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntCmdComponents.dll" named_guids no_namespace
#import "C:\Program Files\FileNet\AppInt\FnAppIntAddViaTemplateCmd.dll" named_guids no_namespace
In the application's primary .cpp source file:
// Instantiate the StdSessionLogin component
IStdSessionLoginPtr spIStdSessionLogin;
HRESULT hResult = spIStdSessionLogin.CreateInstance(__uuidof(StdSessionLogin));
if (FAILED(hResult)) { std::cout << "Could not create the StdSessionLogin component." << std::endl; _ASSERTE(0); } try {
// Initialize the StdSessionLogin component to create // a separate, non-unified login for the client application // by specifying the session / client application name. std::cout << "Initializing the StdSessionLogin component to use NON-unified login..." << std::endl; _bstr_t sessionName(_T("WordPerfect")); spIStdSessionLogin->InitializeViaSessionName(sessionName);
// Instantiate the AppIntSession component
IAppIntSessionPtr spIAppIntSession;
hResult = spIAppIntSession.CreateInstance(__uuidof(AppIntSession)); if (FAILED(hResult)) { std::cout << "Could not create the AppIntSession component." << std::endl; _ASSERTE(0); } // Initialize the AppIntSession component with the StdSessionLogin component
std::cout << "Initializing the AppIntSession component..." << std::endl;
spIAppIntSession->Initialize(spIStdSessionLogin); // * The Client Application may invoke a SessionLogin here; otherwise, // * it will automatically be invoked as needed when commands are executed. std::cout << "Checking Login Status..." << std::endl; VARIANT_BOOL bIsLoggedIn = spIAppIntSession->IsLoggedIn(); if (bIsLoggedIn == VARIANT_TRUE) { std::cout << "User is currently Logged In." << std::endl; } else {
std::cout << "User is NOT currently Logged In." << std::endl;
std::cout << "Attempting Login..." << std::endl;
hResult = spIAppIntSession->Login(); if (FAILED(hResult)) { std::cout << "Login failed." << std::endl; _ASSERTE(0); }
std::cout << "Login succeeded." << std::endl; } // Instantiate the custom SelectEntryTemplate command component // to obtain the desired entry template from the user ISelectEntryTemplateCmdPtr spISelectEntryTemplateCmd;
hResult = spISelectEntryTemplateCmd.CreateInstance(__uuidof(SelectEntryTemplateCmd));
if (FAILED(hResult)) {
std::cout << "Could not create the SelectEntryTemplate command component.\n"; _ASSERTE(0);
} // Initialize the custom SelectEntryTemplate command component with the // page title, object store name, and template type(s). _bstr_t bstrPageTitle = (_T("Customized Select Entry Template Operation")); _bstr_t bstrObjectStoreName = (_T("Alaska")); AppIntTemplateType enTemplateTypes = TemplateTypes_Document; std::cout << "Initializing the SelectEntryTemplate command component..." << std::endl; spISelectEntryTemplateCmd->Initialize(bstrPageTitle, bstrObjectStoreName, enTemplateTypes); // Execute the SelectEntryTemplate command and capture the response component std::cout << "Executing the SelectEntryTemplate command..." << std::endl; IAppIntCmdPtr spIAppIntCmd(spISelectEntryTemplateCmd);
IAppIntRspPtr spIAppIntRsp = spIAppIntCmd->Invoke(spIAppIntSession); // Determine if the command failed, before accessing response component data hResult = spIAppIntRsp->GetHResult(); if (FAILED(hResult)) { std::cout << "The SelectEntryTemplate command failed to execute." << std::endl; // Examine the error information provided in the standard response component _bstr_t bstrErrorName = spIAppIntRsp->GetErrorName(); std::cout << "ErrorName=" << ( bstrErrorName.length() ? (LPCSTR) bstrErrorName : _T( "" ) ) << std::endl; _bstr_t bstrErrorMsg = spIAppIntRsp->GetErrorMsg(); std::cout << "ErrorMsg=" << ( bstrErrorMsg.length() ? (LPCSTR) bstrErrorMsg : _T( "" ) ) << std::endl; _bstr_t bstrErrorDetails = spIAppIntRsp->GetErrorDetails(); std::cout << "ErrorDetails=" << ( bstrErrorDetails.length() ? (LPCSTR) bstrErrorDetails : _T( "" ) ) << std::endl; _ASSERTE(0); } else { std::cout << "The SelectEntryTemplate command succeeded." << std::endl; // Obtain the entry template contained in the custom SelectEntryTemplateRsp component ISelectEntryTemplateRspPtr spISelectEntryTemplateRsp(spIAppIntRsp);
_ASSERTE(spISelectEntryTemplateRsp != 0);
IObjectStoreItemPtr spIObjectStoreItemEntryTemplate = spISelectEntryTemplateRsp->GetObjectStoreItem();
_ASSERTE(spIObjectStoreItem != 0); std::cout << "Details for the entry template selected by the user:<< std::endl;
std::cout << "ObjectStoreName=" << (LPCSTR) spIObjectStoreItemEntryTemplate->GetObjectStoreName() << std::endl;
std::cout << "ItemType=" << (LPCSTR) CItemTypeConverter::EnumToBSTR(spIObjectStoreItemEntryTemplate->GetItemType()) << std::endl;
std::cout << "VersionSeriesID=" << (LPCSTR) spIObjectStoreItemEntryTemplate->GetVersionSeriesID() << std::endl;
std::cout << "VersionID=" << (LPCSTR) spIObjectStoreItemEntryTemplate->GetVersionID() << std::endl; } // Instantiate the custom AddViaTemplate command component IAddViaTemplateCmdPtr spIAddViaTemplateCmd;
hResult = spIAddViaTemplateCmd.CreateInstance(__uuidof(AddViaTemplateCmd));
if (FAILED(hResult)) {
std::cout << "Could not create the AddViaTemplate command component.\n"; _ASSERTE(0);
} // Create the LinkDescriptors for the item to Add const DWORD cNumElements = 2; long lCount = 0; COleSafeArray saLinks(VT_DISPATCH, cNumElements); { // Instantiate a LinkDescriptor component
ILinkDescriptorPtr spILinkDescriptor0(__uuidof(LinkDescriptor)); _ASSERTE(spILinkDescriptor != 0); // Instantiate the ObjectStoreItem component IObjectStoreItemPtr spIObjectStoreItem0; hResult = spIObjectStoreItem0.CreateInstance(__uuidof(ObjectStoreItem));
if (FAILED(hResult)) {
std::cout << "Could not create the ObjectStoreItem component.\n"; _ASSERTE(0);
} // Initialize the ObjectStoreItem component with // the items' type, name, version series ID and version ID. ItemType eItemType = eItemTypeDocument; _bstr_t bstrObjectStoreName = (_T("Alaska")); _bstr_t bstrVersionSeriesID = (_T("{6BC064A2-2D58-4B0A-AEF2-B2F8A1100000}")); _bstr_t bstrVersionID = (_T("{DDE54469-36D9-4fe9-8676-445E4994DE1F}")); std::cout << "Initializing the ObjectStoreItem component..." << std::endl;
spIObjectStoreItem0->Initialize(eItemType, bstrObjectStoreName, bstrVersionSeriesID, bstrVersionID); _bstr_t bstrLinkClassID = (_T("{C91111A9-CE9C-43e6-8548-8A08F43F9726}")); RelationshipType enLinkType = eTypeLinkTo; // Define the XML properties for the item to Link std::cout << "Defining the XML item properties..." << std::endl; _bstr_t bstrLinkPropertiesXml = _T( "" ); bstrLinkPropertiesXml += _T("<properties>");
bstrLinkPropertiesXml += _T("<property>");
bstrLinkPropertiesXml += _T("<symname>DocumentTitle</symname>"); bstrLinkPropertiesXml += _T("<values>");
bstrLinkPropertiesXml += _T("<value>LinkedDocument.doc</value></values>");
bstrLinkPropertiesXml += _T("</property>");
bstrLinkPropertiesXml += _T("<property>");
bstrLinkPropertiesXml += _T("<symname>CommentReq</symname>"); bstrLinkPropertiesXml += _T("<values>");
bstrLinkPropertiesXml += _T("<value>This will be a linked document.</value></values>");
bstrLinkPropertiesXml += _T("</property>");
bstrLinkPropertiesXml += _T("<property>");
bstrLinkPropertiesXml += _T("<symname>SVCPStr</symname>"); bstrLinkPropertiesXml += _T("<values>");
bstrLinkPropertiesXml += _T("<value>This is the SVCPStr property</value></values>");
bstrLinkPropertiesXml += _T("</property>");
bstrLinkPropertiesXml += _T("</properties>");
// Initialize the LinkDescriptor component to hold the link std::cout << "Initializing LinkDescriptor component 1..." << std::endl; spILinkDescriptor0->Initialize(spIObjectStoreItem0, bstrLinkClassID, enLinkType, bstrLinkPropertiesXml); if(spILinkDescriptor0) { saLinks.PutElement(&lCount, spILinkDescriptor0); } } { lCount++; // Instantiate a LinkDescriptor component
ILinkDescriptorPtr spILinkDescriptor1(__uuidof(LinkDescriptor)); _ASSERTE(spILinkDescriptor != 0); // Instantiate the ObjectStoreItem component IObjectStoreItemPtr spIObjectStoreItem1; hResult = spIObjectStoreItem1.CreateInstance(__uuidof(ObjectStoreItem));
if (FAILED(hResult)) {
std::cout << "Could not create the ObjectStoreItem component.\n"; _ASSERTE(0);
} // Initialize the ObjectStoreItem component with // the items' type, name, version series ID and version ID. ItemType eItemType = eItemTypeDocument; _bstr_t bstrObjectStoreName = (_T("Alaska")); _bstr_t bstrVersionSeriesID = (_T("{2400406D-68FE-4d5c-81FD-AC01F7186119}")); _bstr_t bstrVersionID = (_T("{6D770D89-497C-40be-B300-E646FC12DE8A}")); std::cout << "Initializing the ObjectStoreItem component..." << std::endl;
spIObjectStoreItem1->Initialize(eItemType, bstrObjectStoreName, bstrVersionSeriesID, bstrVersionID); _bstr_t bstrLinkClassID = (_T("{C91111A9-CE9C-43e6-8548-8A08F43F9726}")); RelationshipType enLinkType = eTypeLinkTo; // No XML properties for this Link item _bstr_t bstrLinkPropertiesXml = VT_EMPTY; // Initialize the LinkDescriptor component to hold the link std::cout << "Initializing LinkDescriptor component 2..." << std::endl; spILinkDescriptor1->Initialize(spIObjectStoreItem1, bstrLinkClassID, enLinkType, bstrLinkPropertiesXml); if(spILinkDescriptor1) { saLinks.PutElement(&lCount, spILinkDescriptor1); } } _variant_t vLinkDescriptors(saLinks); // Define the XML properties for the item to Add std::cout << "Defining the XML item properties..." << std::endl; _bstr_t bstrPropertiesXml = _T( "" ); bstrPropertiesXml += _T("<properties>");
bstrPropertiesXml += _T("<property>");
bstrPropertiesXml += _T("<symname>DocumentTitle</symname>"); bstrPropertiesXml += _T("<values>");
bstrPropertiesXml += _T("<value>AddedDocument.doc</value></values>");
bstrPropertiesXml += _T("</property>");
bstrPropertiesXml += _T("<property>");
bstrPropertiesXml += _T("<symname>CommentReq</symname>"); bstrPropertiesXml += _T("<values>");
bstrPropertiesXml += _T("<value>This document contains new information to be added.</value></values>");
bstrPropertiesXml += _T("</property>");
bstrPropertiesXml += _T("<property>");
bstrPropertiesXml += _T("<symname>SVCPStr</symname>"); bstrPropertiesXml += _T("<values>");
bstrPropertiesXml += _T("<value>This is the SVCPStr property</value></values>");
bstrPropertiesXml += _T("</property>");
bstrPropertiesXml += _T("</properties>");// Initialize the custom AddViaTemplate command component with the dialog title, // name and directory location of the file on the local machine, // the entry template selected by the user, // as well as the XML properties and LinkDescriptors. _bstr_t bstrDialogTitle = (_T("Customized AddViaTemplate Operation")); _bstr_t bstrPathName = (_T("C:\Temp\DocumentToBeAdded.doc")); VARIANT_BOOL bDeclareRecordOn = VARIANT_FALSE; _variant_t vDocumentIDs(); std::cout << "Initializing the AddViaTemplate command component..." << std::endl; spIAddViaTemplateCmd->Initialize(bstrDialogTitle, bstrPathName, spIObjectStoreItemEntryTemplate, bstrPropertiesXml, vLinkDescriptors, bDeclareRecordOn, vDocumentIDs);
// Execute the AddViaTemplate command and capture the response component std::cout << "Executing the AddViaTemplate command..." << std::endl; IAppIntCmdPtr spIAppIntCmd(spIAddViaTemplateCmd);
IAppIntRspPtr spIAppIntRsp = spIAppIntCmd->Invoke(spIAppIntSession); // Determine if the command failed, before accessing response component data hResult = spIAppIntRsp->GetHResult(); if (FAILED(hResult)) { std::cout << "The AddViaTemplate command failed to execute." << std::endl; // Examine the error information provided in the standard response component _bstr_t bstrErrorName = spIAppIntRsp->GetErrorName(); std::cout << "ErrorName=" << ( bstrErrorName.length() ? (LPCSTR) bstrErrorName : _T( "" ) ) << std::endl; _bstr_t bstrErrorMsg = spIAppIntRsp->GetErrorMsg(); std::cout << "ErrorMsg=" << ( bstrErrorMsg.length() ? (LPCSTR) bstrErrorMsg : _T( "" ) ) << std::endl; _bstr_t bstrErrorDetails = spIAppIntRsp->GetErrorDetails(); std::cout << "ErrorDetails=" << ( bstrErrorDetails.length() ? (LPCSTR) bstrErrorDetails : _T( "" ) ) << std::endl; _ASSERTE(0); } else { std::cout << "The AddViaTemplate command succeeded." << std::endl; // Obtain the response name and description from the standard response component _bstr_t bstrResponseDescription = spIAppIntRsp->GetDescription(); std::cout << "ResponseDescription=" << ( bstrResponseDescription.length() ? (LPCSTR) bstrResponseDescription : _T( "" ) ) << std::endl; _bstr_t bstrResponseName = spIAppIntRsp->GetName(); std::cout << "ResponseName=" << ( bstrResponseName.length() ? (LPCSTR) bstrResponseName : _T( "" ) ) << std::endl; // Obtain the specific response information contained in the custom AddRsp component IAddViaTemplateRspPtr spIAddViaTemplateRsp(spIAppIntRsp);
_ASSERTE(spIAddViaTemplateRsp != 0);
IObjectStoreItemPtr spIObjectStoreItemAdded = spIAddViaTemplateRsp->GetObjectStoreItem();
_ASSERTE(spIObjectStoreItemAdded != 0);
std::cout << "ObjectStoreName=" << (LPCSTR) spIObjectStoreItemAdded->GetObjectStoreName() << std::endl;
std::cout << "ItemType=" << (LPCSTR) CItemTypeConverter::EnumToBSTR(spIObjectStoreItemAdded->GetItemType()) << std::endl;
std::cout << "VersionSeriesID=" << (LPCSTR) spIObjectStoreItemAdded->GetVersionSeriesID() << std::endl;
std::cout << "VersionID=" << (LPCSTR) spIObjectStoreItemAdded->GetVersionID() << std::endl; } } catch(...) { }