WBSFillOpportunity

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.wbs { 	/// <summary>
	/// Summary description for WBSFillOpportunity.
	/// 
	/// this sample loads a Project and fills the opportunity
	/// then saves the project back to the RPM repository
	/// </summary>
	public class WBSFillOpportunity
	{
		public WBSFillOpportunity()
		{

		}

		public static String projectName = "IBM_GENERIC_PROJECT_ABC";
		public static String conNumber = "IBM_CONTACT_NUMBER";
		public static String conType = "IBM_CONTACT_TYPE";
		public static String cusNumber = "IBM_CUSTOMER_NUMBER";
		public static String exClient = "IBM_EXTERNAL_CLIENT";
		public static String oppOwner = "IBM_OPPORTUNITY_OWNER";
		public static String oppTrNumber = 
						"IBM_OPPORTUNITY_TRACKING_NUMBER";
		public static int benBegin = 14;
		public static int benDuration = 10;
		public static double magnitude = 100000.00;
		
		//Session ID is use for all transaction and is get from the 
		//Authenticate.login function. The session ID will replace 
		// the User password while transacting
		public static String sessionid;

		public void sampleTest() 
		{

			// initialize a session with the API
			sessionid = APISetup.SetUp();

			// create a save result object 
			SaveResult save = null;

			// create a project scope
			// this scope enables us to work with a project and 
			// any child object we wish to use
			WorkElementScope weScope = new WorkElementScope();

			// create a project object that we will use to either 
			// create one or load one project
			Project project = null;

			// adjust project scope so it includes opportunity
			weScope.opportunity = true;

			// query the project
			project = (Project)APISetup.application.
				loadFromXpath(sessionid, 
				"/Project[name='" + projectName + "']", 
				weScope ).rpmObjectList[0];
 
			project.opportunity = new Opportunity();
			// initialize opportunity object
			project.opportunity.forecastClosed = 
				new DateTime(2008, 10,10,10,10,10,10);
			project.opportunity.pursuitFinish = 
				new DateTime(2008, 10,10,10,10,10,10);
			project.opportunity.pursuitStart = 
				new DateTime(2006, 10,10,10,10,10,10);

			project.opportunity.benefitBeginsMonths = benBegin;
			project.opportunity.benefitDurationMonths = benDuration;
			project.opportunity.orderOfMagnitudeCost = magnitude;

			project.opportunity.contactNumber = conNumber;
			project.opportunity.contactType = conType;
			project.opportunity.customerNumber = cusNumber;
			project.opportunity.externalClient = exClient;
			project.opportunity.opportunityOwner = oppOwner;
			project.opportunity.opportunityTrackingNumber = 
				oppTrNumber;

			project.opportunity.parent = project;

			// save the project into the RPM repository
			// a scope is necessary to keep the opportunity 
			// linked with the portfolio
			save = new SaveResult();
			save = APISetup.application.save(sessionid, 
				project, weScope, ReloadType.None);
			APISetup.checkForErrors( save );

			// close connection with API
			APISetup.CleanUp(sessionid);
		}

	}
}