Create Global Functions

Global functions are used to wrap business logic around the web services so that they can easily be used in other locations.

OCMCreateRepositoryCollectionFunction

To create the OCM Create Repository Collection global function that will be used to access the OCMCreateRepositoryCollectionService web service:

  1. Choose Common Setup and then Global Functions from the left navigation menu.
  2. On the Global Functions page, click the Add a Global Function icon.
  3. On the Create Global Function page, complete the following fields:

    1. In the Function Name field, specify the name of the function as OCMCreateRepositoryCollectionFunction.
    2. Select String from the Returns drop-down menu.
    3. In the Description field, enter the text “Creates a new OCMCollectionName within the specified OCMRepositoryId and returns the newly created Collection Id.”.
    4. In the Parameters section, click the Add Parameter icon and add the following fields:
      Name Type
      OCMRepositoryId String
      OCMCollectionName String
    5. In the Edit Script field, paste the following script:
      println("Create OCM Collection " + OCMCollectionName + " within the Asset Repository Id: " + OCMRepositoryId);
      def params = [:]
      params.name = OCMCollectionName
      def OCMCollection = [:]
      try {
        def OCMCreateRepositoryCollectionService = adf.webServices.OCMCreateRepositoryCollectionService
        OCMCreateRepositoryCollectionService.requestHTTPHeaders = ['X-Requested-With': 'XMLHttpRequest']
        OCMCollection = OCMCreateRepositoryCollectionService.POST(OCMRepositoryId, params)
        println("OCM Collection Created: " + OCMCollection)
        return OCMCollection.id
      } catch (Exception e) {
        println("OCM Create Respository(" + OCMRepositoryId + ") Collection(" + OCMCollectionName + ") Error: " + e)
      }
    6. Click Save and Close.

OCMGetDocumentsByFolderIdFunction

To create the OCM Get Documents By Folder Id global function in a new Create Global Function page that will be used to access the OCMGetDocumentsByFolderIdService web service, complete the following fields:

Note:

This global function is only required if the Oracle Sales and Service business object has the resolve option and has been configured with OCM Document integration. See Learn About How to Extend Oracle Sales and Service Business Objects with Document Collaboration for more information on Document Integration.


  1. In the Function Name field, specify the name of the function as OCMGetDocumentsByFolderIdFunction.
  2. Select List from the Returns drop-down menu.
  3. In the Description field, enter the text “Returns a list of OCM Document Id's based off the specified OCMFolderId (this includes child folders as well).”.
  4. In the Parameters section, click the Add Parameter icon.

    In the Name field, specify the name as OCMFolderId and select String from the Type drop-down menu.

  5. In the Edit Script field, paste the following script:
    def response = [:]
    def items = []
    try {
      response = adf.webServices.OCMGetDocumentsByFolderIdService.GET(OCMFolderId)
      for(item in response.items){
        items.add(item["id"])
      }
      println("OCM Get Documents By Folder Id " + OCMFolderId + " Result(" + items.size() + "): " + items)
      return items
    } catch (Exception e) {
      println("Get OCM Documents By Folder Id Error: " + e)
    }
    
  6. Click Save and Close.

OCMCopyDocumentsToRepositoryCollectionFunction

To create the OCM Copy Documents To Repository Collection global function in a new Create Global Function page that will be used to access the OCMBulkOperationsService web service, complete the following fields:

Note:

This global function is only required if the Oracle Sales and Service business object has the resolve option and has been configured with OCM Document integration. See Learn About How to Extend Oracle Sales and Service Business Objects with Document Collaboration for more information on Document Integration.


  1. In the Function Name field, specify the name of the function as OCMCopyDocumentsToRepositoryCollectionFunction.
  2. Select Boolean from the Returns drop-down menu.
  3. In the Description field, enter the text “Copies the OCM specified list of OCMDocumentIds into the specified OCMCollectionId within the specified OCMRepositoryId.”.
  4. In the Parameters section, click the Add Parameter icon and add the following fields:
    Name Type
    OCMRepositoryId String
    OCMCollectionId String
    OCMDocumentIds List
  5. In the Edit Script field, paste the following script:
    // Create the structure required for the list of documents that will be used in the payload below
    def documents = []
    for(OCMDocumentId in OCMDocumentIds) {
      def document = 
      [
        externalId: OCMDocumentId,
        // NOTE: The type value must match the name of the Asset Type that you created during the installation
        type: "Service-Request-Asset",
        collections:
        [
          data: [OCMCollectionId]
        ]
      ]
      
      documents.add(document)
    }
    
    // Create the payload required to make the addToRepository bulk operation call
    def payload =
    [
      operations:
      [
        addToRepository:
        [
          connectorId: "Documents",
          repositoryId: OCMRepositoryId,
          externalItems: documents
        ]
      ]
    ]
    
    try {
      def OCMBulkOperationsService = adf.webServices.OCMBulkOperationsService  
      OCMBulkOperationsService.requestHTTPHeaders = ['X-Requested-With': 'XMLHttpRequest']
      OCMBulkOperationsService.POST(payload)
      println("OCM Documents Copied To Repository: " + OCMRepositoryId + "(" + OCMCollectionId + "): (" + OCMDocumentIds + ")")
      return true
    } catch (Exception e) {
      println("Copy OCM Documents To Repository Error: " + e)
      return false 
    }

    Note:

    The Type value in the script above must match the name of the asset type you created previously.
  6. Click Save and Close.

OCMIsRepositoryCollectionSharedAsContributorFunction

To create the OCM Is Repository Collection Shared As Contributor global function in a new Create Global Function page that will be used to access the OCMRepositoryCollectionPermissionsService web service, complete the following fields:



  1. In the Function Name field, specify the name of the function as OCMIsRepositoryCollectionSharedAsContributorFunction.
  2. Select Boolean from the Returns drop-down menu.
  3. In the Description field, enter the text “Returns true if the specified OCMUserName has been shared to the specified OCMCollectionId within the specified OCMRespositoryId with at least a Contributor role.”.
  4. In the Parameters section, click the Add Parameter icon and add the following fields:
    Name Type
    OCMRepositoryId String
    OCMCollectionId String
    OCMUserName String
  5. In the Edit Script field, paste the following script:
    def response = [:]
    try {
      response = adf.webServices.OCMRepositoryCollectionPermissionsService.GET(OCMRepositoryId, OCMCollectionId)
      def responseItems = [:]
      responseItems = response.items
      for (item in responseItems) {
        // Ignore case as these could be different between the two security systems even though it is the same user
        if ((item['id'] as String).toLowerCase() == OCMUserName.toLowerCase()) {
          // If found make sure the user also has at least the contributor role
          if (item['roleName'] == 'contributor' || item['roleName'] == 'manager') {
            println("OCM User(" + OCMUserName + ") was found with enough role permissions to the repository collection: " + OCMRepositoryId + "(" + OCMCollectionId + ")")
            return true
          } else {
            println("OCM User(" + OCMUserName + ") was found but without enough role permissions to the repository collection: " + OCMRepositoryId + "(" + OCMCollectionId + ")")
            return false
          }
        }
      }
      println("OCM User(" + OCMUserName + ") does not have permissions to the repository: " + OCMRepositoryId)
      return false
    } catch (Exception e) {
      println("OCM Is Repository Collection Shared As Contributor Error: " + e)
      return false
    }
  6. Click Save and Close.

OCMShareCollectionFunction

To create the OCM Share Collection global function in a new Create Global Function page that will be used to access the OCMPermissionOperationsService web service, complete the following fields:



  1. In the Function Name field, specify the name of the function as OCMShareCollectionFunction.
  2. Select Boolean from the Returns drop-down menu.
  3. In the Description field, enter the text “Shares the specified OCMCollectionId in OCM with the OCMUserName and OCMRole specified.”.
  4. In the Parameters section, click the Add Parameter icon and add the following fields:
    Name Type
    OCMCollectionId String
    OCMUserName String
    OCMRole String
  5. In the Edit Script field, paste the following script:
    // Create the payload required to make the permissions operation call
    def payload =
    [
      operations:
      [
        share:
        [
          resource:
          [
            id :OCMCollectionId,
            type :"collection",
          ],
          roles:
          [[
            name :OCMRole,
            users:
            [[
              name :OCMUserName,
              type :"user",
            ]],
          ]],
        ],
      ]
    ]
    
    def response = [:]
    try {
      def OCMPermissionOperationsService = adf.webServices.OCMPermissionOperationsService
      OCMPermissionOperationsService.requestHTTPHeaders = ['X-Requested-With': 'XMLHttpRequest', 'content-type': 'application/json']
      response = OCMPermissionOperationsService.POST(payload)
      
      // Check the response to make sure we do not have a failure
      def hasFailedRoles = response?.operations?.share?.failedRoles
      if (hasFailedRoles == null) {
        println("OCM Collection Shared: " + OCMCollectionId + "(" + OCMUserName + ":" + OCMRole + ")")
        return true
      } else {
        println("Share OCM Collection Failed: " + response)
        return false
      }
    } catch (Exception e) {
      println("Share OCM Collection Error: " + e)
      return false 
    }
    
  6. Click Save and Close.