Create Global Functions

Now you create the following global functions that will be used in an object workflow groovy script.

Create the findSelfServiceUserLoginId Global Function

Use this topic to create the findSelfServiceUserLoginId global function.

  1. In Application Composer, expand Common Setup, and select Global Functions.

  2. Click the Add a Global Function icon.

  3. Use the following table to fill in the necessary fields:

    Field

    What You Do

    Function Name

    Enter: findSelfServiceUserLoginId

    Returns

    Click the drop down list and select String.

    Parameters

    1. Click to expand the workspace.

    2. Click the Add Parameter icon.

    3. In the Name field enter: contactPartyId.

    4. From the Type drop down list, select String.

  4. In the Edit Script field, copy and paste the following script:

    def request = adf.webServices.FindSelfServiceUser
     
    try{
      def httpHeaders=['REST-Framework-Version':'3']
      request.requestHTTPHeaders = httpHeaders
       
      def searchResults = request.GET(contactPartyId)
      def count = searchResults.get("count")
       
      if(count == 0){
        def message = "Unable to locate self-service user by Party ID: " + contactPartyId + ":" + searchResults
        throw new oracle.jbo.ValidationException(message);
      }
       
      def loginId = searchResults.get("items")[0].get("LoginId")
       
      return loginId
    }catch(Exception e){
      throw new oracle.jbo.ValidationException(" " + e + ": " + request.httpErrorResponse)
    }
  5. Click Save and Close.

  6. Click Yes to accept the warning message.

Create the getIdcsUserGuid Global Function

Use this topic to create the getIdcsUserGuid global function.

  1. In Application Composer, expand Common Setup, and select Global Functions.

  2. Click the Add a Global Function icon.

  3. Use the following table to fill in the necessary fields:

    Field

    What You Do

    Function Name

    Enter: getIdcsUserGuid

    Returns

    Click the drop down list and select String.

    Parameters

    1. Click to expand the workspace.

    2. Click the Add Parameter icon.

    3. In the Name field enter: loginId.

    4. From the Type drop down list, select String.

  4. In the Edit Script field, copy and paste the following script:

    def request = adf.webServices.FindIdcsGuidByLoginId
     
    try{
      def searchResults = request.GET(loginId)
      def totalResults = searchResults.get("totalResults")
       
      if(totalResults != 1){
        throw new oracle.jbo.ValidationException("Unable to locate user by login ID: " + loginId + ", total results: " + totalResults);
      }
       
      def resources = searchResults.get("Resources")
      def user = resources[0]
      def guid = user.get("id")
       
      return guid;
    }catch(Exception e){
      throw new oracle.jbo.ValidationException("Error finding IDCS User: " + e + ":" +request.httpErrorResponse);
    }
  5. Click Save and Close.

  6. Click Yes to accept the warning message.

Create the updateUserAttributesInIdcs Global Function

Use this topic to create the getIdcsUserGuid global function.

  1. In Application Composer, expand Common Setup, and select Global Functions.

  2. Click the Add a Global Function icon.

  3. Use the following table to fill in the necessary fields:

    Field

    What You Do

    Function Name

    Enter: updateUserAttributesInIdcs

    Returns

    Click the drop down list and select void.

    Parameters

    1. Click to expand the workspace.

    2. Click the Add Parameter icon.

    3. In the Name field enter:userId.

    4. From the Type drop down list, select String.

    5. Click the Add Parameter icon.

    6. In the Name field enter: firstName.

    7. From the Type drop down list, select String.

    8. Click the Add Parameter icon.

    9. In the Name field enter: lastName.

    10. From the Type drop down list, select String.

  4. In the Edit Script field, copy and paste the following script:

    def conn = adf.webServices.UpdateIdcsUserAttributes
    try{
    def patch_body = [
      "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:PatchOp"
      ],
      "Operations": [
      [
        "op": "replace",
        "path": "name",
        "value":
        [
          "givenName": firstName,
          "familyName": lastName
        ]
      ]
      ]
    ]
    conn.PATCH(userId, patch_body)
    }catch(Exception e){
      throw new oracle.jbo.ValidationException(" " + e + " " + conn. httpErrorResponse)
    }
  5. Click Save and Close.

  6. Click Yes to accept the warning message.

Create the syncContactAttributes Global Function

Use this topic to create the getIdcsUserGuid global function.

  1. In Application Composer, expand Common Setup, and select Global Functions.

  2. Click the Add a Global Function icon.

  3. Use the following table to fill in the necessary fields:

    Field

    What You Do

    Function Name

    Enter: syncContactAttributes

    Returns

    Click the drop down list and select void.

    Parameters

    1. Click to expand the workspace.

    2. Click the Add Parameter icon.

    3. In the Name field contactPartyId.

    4. From the Type drop down list, select String.

    5. Click the Add Parameter icon.

    6. In the Name field enter: firstName.

    7. From the Type drop down list, select String.

    8. Click the Add Parameter icon.

    9. In the Name field enter: lastName.

    10. From the Type drop down list, select String.

  4. In the Edit Script field, copy and paste the following script:

    def loginId = adf.util.findSelfServiceUserLoginId(contactPartyId)
    def userGuid = adf.util.getIdcsUserGuid(loginId)
    adf.util.updateUserAttributesInIdcs(userGuid,firstName,lastName)
  5. Click Save and Close.

  6. Click Yes to accept the warning message.