Write the invoking JavaScript code

Now that the generated JavaScript gave information on the structure of the code to use for invoke, write the invoking JavaScript code. In this case, the invoking code gets passed in information from a Service Catalog Item. This information is then processed and passed through to the PPM Web Service.

function CreateDemandRequest(CartItem)
{

	try
	{
/////////////////////////////////////////////////////////////////////
//    Initialization Section
//////////////////////////////////////////////////////////////////
//		first, initialize the Service Object for this JavaScript
		var DemandService=new system.library.DemandService.DemandService();

	
//		set Connection information (optional)
		DemandService.user = "admin";
		DemandService.password = "admin";
//		DemandService.location="http://<ppm server>:15000
                 /itg/ppmservices/DemandService";
		DemandService.location="http://localhost:15001
                 /itg/ppmservices/DemandService";

//		create the request object
		var RequestDemRequest = 
                 new system.library.DemandService.createRequest();


////////////////////////////////////////////////////////////////////////
//     Data Fill Section
////////////////////////////////////////////////////////////////////////

// Data from Cart Item

	 	var PlannedStart=system.library.xmlFill.
                getValue(CartItem.options, "PlannedStart");
 		var PlannedEnd=system.library.xmlFill.
                getValue(CartItem.options, "PlannedEnd");
 		var ProjectName=system.library.xmlFill.
                getValue(CartItem.options, "ProjectName");
 		var ProjectManager=system.library.xmlFill.getValue
            (CartItem.options, "ProjectManager");
 		var Region=system.library.xmlFill.getValue
                (CartItem.options, "Region");
 		var ProjectType=system.library.xmlFill.getValue
                (CartItem.options, "ProjectType");

// Fill into Web Request
 		RequestDemRequest.requestObj.requestType.setValue
               ( "PFM - Proposal" );
 		
 		RequestDemRequest.requestObj.simpleFields_newInstance();
 		
		RequestDemRequest.requestObj.simpleFields[0].token.setValue
                ("REQ.VP.KNTA_PLAN_START_DATE");
		 var String0=RequestDemRequest.requestObj.simpleFields[0]
                .stringValue_newInstance();
		String0.setValue(PlannedStart)
		RequestDemRequest.requestObj.simpleFields_newInstance();
		
 		RequestDemRequest.requestObj.simpleFields[1].token.setValue
                 ("REQ.VP.KNTA_PLAN_FINISH_DATE");
 		var String1=RequestDemRequest.requestObj.simpleFields[1]
                  .stringValue_newInstance();
		String1.setValue(PlannedEnd)
		
		RequestDemRequest.requestObj.simpleFields_newInstance();
 		RequestDemRequest.requestObj.simpleFields[2].token.setValue
                ("REQ.VP.KNTA_PROJECT_NAME");
 		var String2=RequestDemRequest.requestObj.simpleFields[2]
                .stringValue_newInstance();
		String2.setValue(ProjectName)

 		RequestDemRequest.requestObj.simpleFields_newInstance();
 		RequestDemRequest.requestObj.simpleFields[3].token
                 .setValue("REQ.VP.KNTA_PROJECT_MANAGER");
		var String3=RequestDemRequest.requestObj.simpleFields[3]
                 .stringValue_newInstance();
		String3.setValue(ProjectManager)

		RequestDemRequest.requestObj.simpleFields_newInstance();
 		RequestDemRequest.requestObj.simpleFields[4].token
                  .setValue("REQ.VP.KNTA_REGION");
		var String4=RequestDemRequest.requestObj.simpleFields[4]
                  .stringValue_newInstance();
		String4.setValue(Region)
		
		RequestDemRequest.requestObj.simpleFields_newInstance();
 		RequestDemRequest.requestObj.simpleFields[5].token.setValue
                 ("REQ.VP.KNTA_PROJECT_TYPE");
		var String5=RequestDemRequest.requestObj.simpleFields[5]
                 .stringValue_newInstance();
		String5.setValue(ProjectType)

//		var ProjectNotes=RequestDemRequest.requestObj.
                  notes_newInstance();
//		ProjectNotes.content.setValue("notes");
RequestDemRequest.requestObj.simpleFields[4].token.getValue())

/////////////////////////////////////////////////////////////////////////
//     Invoke and final processing
/////////////////////////////////////////////////////////////////////////
		var DemandResponse = DemandService.invoke
               ( RequestDemRequest );
	
		if ( DemandResponse.isFault() )
		{
            print( DemandResponse.faultcode.getValue() );
            print( DemandResponse.faultstring.getValue() );
            print( DemandResponse.detail.getValue() );              
            return("Failure");
		}
		else 
		{  
			print("Success")
   			return("Success");
		}
	
	}
	catch( e )
	{
		print( e );
	}
	
}

////////////////////////////////////////////////////////////////////////
// Test Call
/////////////////////////////////////////////////////////////////////////

//var rc_Code=CreateDemandRequest(CartItem);