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.
-
In Application Composer, expand Common Setup, and select Global Functions.
-
Click the Add a Global Function icon.
-
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
-
Click to expand the workspace.
-
Click the Add Parameter icon.
-
In the Name field enter: contactPartyId.
-
From the Type drop down list, select String.
-
-
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) }
-
Click Save and Close.
-
Click Yes to accept the warning message.
Create the getIdcsUserGuid Global Function
Use this topic to create the getIdcsUserGuid global function.
-
In Application Composer, expand Common Setup, and select Global Functions.
-
Click the Add a Global Function icon.
-
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
-
Click to expand the workspace.
-
Click the Add Parameter icon.
-
In the Name field enter: loginId.
-
From the Type drop down list, select String.
-
-
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); }
-
Click Save and Close.
-
Click Yes to accept the warning message.
Create the updateUserAttributesInIdcs Global Function
Use this topic to create the getIdcsUserGuid global function.
-
In Application Composer, expand Common Setup, and select Global Functions.
-
Click the Add a Global Function icon.
-
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
-
Click to expand the workspace.
-
Click the Add Parameter icon.
-
In the Name field enter:userId.
-
From the Type drop down list, select String.
-
Click the Add Parameter icon.
-
In the Name field enter: firstName.
-
From the Type drop down list, select String.
-
Click the Add Parameter icon.
-
In the Name field enter: lastName.
-
From the Type drop down list, select String.
-
-
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) }
-
Click Save and Close.
-
Click Yes to accept the warning message.
Create the syncContactAttributes Global Function
Use this topic to create the getIdcsUserGuid global function.
-
In Application Composer, expand Common Setup, and select Global Functions.
-
Click the Add a Global Function icon.
-
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
-
Click to expand the workspace.
-
Click the Add Parameter icon.
-
In the Name field contactPartyId.
-
From the Type drop down list, select String.
-
Click the Add Parameter icon.
-
In the Name field enter: firstName.
-
From the Type drop down list, select String.
-
Click the Add Parameter icon.
-
In the Name field enter: lastName.
-
From the Type drop down list, select String.
-
-
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)
-
Click Save and Close.
-
Click Yes to accept the warning message.