Integrate > Service Manager integration methods and tools > Web Services > SOAP API > Consuming a Service Manager Web Service > Example: Getting change information from another Service Manager system

Example: Getting change information from another Service Manager system

This example retrieves change information from the cm3r file and uses the Web Service to create a new change.

  1. Click Tailoring > Web Services > Run WSDL to JS.
  2. In the “Please enter the URL for the WSDL file” field, enter the following:

    http://<serenade>:<port number>/sc62server/PWS/ChangeManagement.wsdl

  3. Click Proceed and then Add to create the ChangeManagement JavaScript record in the ScriptLibrary.

    Note Service Manager always uses the user name and password you provided to access the remote Web Service unless you override the values at run time. For example, create custom JavaScript to use the currently logged in user's credentials instead of the user name and password you provided to access the remote Web Service.

    	function ChangeManagement( )
    	{
    	this.location = new String( "http://hostname:13080/sc62server/ws" );
    
    	this.user = null;
    	this.password = null;
    	this.connectTimeOut = 10;
    	this.sendTimeOut = 10;
    	this.recvTimeOut = 10;
    	this.soapEnvelope = null;
    	this.soapBody = null;
    	this.soapHeader = null;
    	this.attachments = new Array();
    	this.resultXML = null;
    	this.invoke = invoke;
    	[…]
    			
    

    Note The namespace specified in “this.location” does not have to be resolvable.

    The user can be filled in here (this.user), or in the invoking script. As a best practice, fill in the user in the invoking script.

  4. Now that the Script has been added to the ScriptLibrary, you need to write another JavaScript that can be used to retrieve the change or create a new change. Enter the JavaScript code as listed below:

    function RetrieveChangeKeysList(query)
    {
    try
    {
    var ChangeMgmtService=new system.library.ChangeManagement.
    ChangeManagement();
    
    /////////////////////////////////////////////////////////	
    //		set Connection information (optional)
    /////////////////////////////////////////////////////////
    ChangeMgmtService.user = "falcon";
    ChangeMgmtService.password = "";
    
    
    /////////////////////////////////////////////////////////
    //	create the request object
    /////////////////////////////////////////////////////////
    var RetrieveChangeListRequest = new system.library.
    ChangeManagement.RetrieveChangeKeysListRequest();
    
    
    /////////////////////////////////////////////////////////
    //		Request Data Fill Section
    //////////////////////////////////////////////////////////////////////// 
    
    if (query!=null)
    {
    RetrieveChangeListRequest.model.instance.query=query;
    }
    else
    print("Please enter a valid Query statement.")
    
    
    ////////////////////////////////////////////////////////////////////////
    //     Invoke and final processing
    ////////////////////////////////////////////////////////////////////////
    var RetrieveChangesResponse = ChangeMgmtService.invoke( RetrieveChangeListRequest );
    	
    if ( RetrieveChangesResponse.isFault() )
    {
    print( RetrieveChangesResponse.messages.getContent() );
    return(-1);
    }
    else 
    {  
    print("Success")
    print(RetrieveChangesResponse.keys[0].ChangeNumber.getValue())
    print(RetrieveChangesResponse.keys[1].ChangeNumber.getValue())
    return(RetrieveChangesResponse.keys);
    }
    	
    }
    catch( e )
    {
    print( e );
    }
    	
    }
    
    function RetrieveChange(number)
    {
    try
    {
    var ChangeMgmtService=new system.library.ChangeManagement.ChangeManagement();
    
    ////////////////////////////////////////////////////////////////////////
    //		set Connection information (optional)
    ////////////////////////////////////////////////////////////////////////
    ChangeMgmtService.user = "falcon";
    ChangeMgmtService.password = "";
    		
    
    ////////////////////////////////////////////////////////////////////////
    //		create the request object
    ////////////////////////////////////////////////////////////////////////
    var RetrieveChangeRequest = new system.library.ChangeManagement.
    RetrieveChangeRequest();
    
    ////////////////////////////////////////////////////////////////////////
    //     Request Data Fill Section
    ////////////////////////////////////////////////////////////////////////
    
    if (number!=null)
    {
    RetrieveChangeRequest.model.instance.header.ChangeNumber.setValue(number);
    }
    else
    print("Please pass in a valid Change Number.");
    
    ////////////////////////////////////////////////////////////////////////
    //     Invoke and final processing
    ////////////////////////////////////////////////////////////////////////
    var RetrieveChangeResponse = ChangeMgmtService.invoke( RetrieveChangeRequest );
    	
    if ( RetrieveChangeResponse.isFault() )
    {
    print( RetrieveChangeResponse.messages.getContent() );
    return(-1);
    }
    else 
    {  
    print("Success")
    return(RetrieveChangeResponse.model.instance);
    }
    	
    }
    catch( e )
    {
    print( e );
     }
    	
    }
    				
    
  5. Create a JavaScript in the same ScriptLibrary record that reads a change record and then creates a new record in the other Service Manager system. Enter the Java Script shown below:

    							
    
    	function CreateChangeFromChange(change)
    {
    	try
    	{
    		var ChangeMgmtService=new system.library.ChangeManagement.
    		ChangeManagement();
    
    /////////////////////////////////////////////////////////////////////////
    //		set Connection information (optional)
    /////////////////////////////////////////////////////////////////////////
    		ChangeMgmtService.user = "falcon";
    		ChangeMgmtService.password = "";
    		
    /////////////////////////////////////////////////////////////////////////
    //		create the request object
    /////////////////////////////////////////////////////////////////////////
    		var CreateChangeRequest = new system.library.ChangeManagement.
    		CreateChangeRequest();
    
    
    /////////////////////////////////////////////////////////////////////
    //     Request Data Fill Section
    /////////////////////////////////////////////////////////////////////
    
    		if (change!=null)
    		{
    			CreateChangeRequest.model.instance.header.Category.
    			setValue(change.header.Category.getValue());
    			CreateChangeRequest.model.instance.header.RequestedBy.
    			setValue(change.header.RequestedBy.getValue());
    			CreateChangeRequest.model.instance.header.Reason.
    			setValue(change.header.Reason.getValue());
    			CreateChangeRequest.model.instance.header.Coordinator.
    			setValue(change.header.Coordinator.getValue());
    			CreateChangeRequest.model.instance.InitialAssessment.
    			setValue(change.InitialAssessment.getValue());
    			CreateChangeRequest.model.instance.Urgency.
    			setValue(change.Urgency.getValue());
    			CreateChangeRequest.model.instance.ReleaseType.
    			setValue(change.ReleaseType.getValue());
    			
    			for (var i=0; i<change.description_structure.
    			Description.Description.length; i++)
    			{
    		CreateChangeRequest.model.instance.description_structure.
    			Description.Description_newInstance().
    			setValue(change.description_structure.Description.
    			Description[i].getValue());
    			}
    		}
    		else
    			print("Please pass in a valid Change Request.");
    
    
    //////////////////////////////////////////////////////////////////////
    //     Invoke and final processing
    //////////////////////////////////////////////////////////////////////
    		var CreateChangeResponse = ChangeMgmtService.
    		invoke( CreateChangeRequest );
    	
    		if ( CreateChangeResponse.isFault() )
    		{
                print( CreateChangeResponse.messages.getContent() );
                return(-1);
    		}
    		else 
    		{  
    			print("Success")
       			return(CreateChangeResponse.model.instance.header.
    			ChangeNumber.getValue());
    		}
    	
    	}
    	catch( e )
    	{
    		print( e );
    	}
    }
    	
    

    The following section shows how to call the above WebServices from JavaScript:

    ///////////////////////////////////////////////////////////////////////
    // Test Call
    ///////////////////////////////////////////////////////////////////////
    var rc_Code_List=RetrieveChangeKeysList("category=\"" + "Release Management"
    	 + "\"" + "and number <=\"" + "C10027" + "\"");
    
    //var rc_Code_List=RetrieveChangeKeysList("number>=\"" + "C10026" + "\"");
    
    if (rc_Code_List != -1)
    {
    	for (var i = 0; i < rc_Code_List.length; i+=1)
    	{
    		var rc_Code=RetrieveChange(rc_Code_List[i].ChangeNumber.
    		getValue());
    		var rc_Create=CreateChangeFromChange(rc_Code);
    	}
    }