How can I map more fields from the SR to work orders?

This example shows you how you can map extra fields from service request to a work order. For example map the title of the SR to the work order.

Note: This example assumes that custom fields are already mapped in the layouts.

Create a New Action Chain on VB Enter

  1. Navigate to AppUIs tab > Expand Oracle CX Service UI Extension App > Service > fieldsvc > Create page.
  2. Navigate to Event Listeners > Create a new Event Listener on VBEnter > Create page Action chain (with JSON format). For example, vbEnterChangeListener.json
Note:

By default VB will generate in Javascript format. Change it to the JSON format.

Create-page.json-x file generates lines as shown in the following code:

Create-page.json-x


"vbEnter": {
  "chains": [
    {
      "parameters": {},
      "chainId": "vbEnterChangeListener"
    }
  ]
}

Assign Fields in Action Chain

  1. Navigate to the action chain created in the previous step and add this logic:
    1. Assign 'fetchSRDetails' = true
    2. Assign 'fetchOtherSRFields' = <SR Field names with coma separated>
Note:

The field name should match with the service request object. For example: CustomText_c,CustomText_c_2. The Action chain JSON file looks like the following code:

vbEnterChangeListener.json

"actions": {
  "assignVariablesFetchSRDetails": {
    "module": "vb/action/builtin/assignVariablesAction",
    "parameters": {
      "$base.page.variables.fetchSRDetails": {
        "source": true
      }
    },
    "outcomes": {
      "success": "assignVariables"
    }
  },
  "assignVariables": {
    "module": "vb/action/builtin/assignVariablesAction",
    "parameters": {
      "$base.page.variables.fetchOtherSRFields": {
        "source": "{{'CustomText_c','CustomText_c_2'}}"
      }
    }
  }
}

Create Action Chain for Page Event and Add Input Parameters

  1. Navigate to Event Listeners > Create a new Event Listener for the page Event 'fetchSRDetails' > Create page Action chain with JSON format. For example fetchSRDetailsChangeListener.json
Note:

By default VB will generate Javascript format. You need to change this to JSON format.

Declare input parameter as 'srObj' for action chain > $event.srObj (map 'event.srOb'j object to input parameter).

create-page-x.json


"oracle_cx_serviceUI/page:fetchSRDetails": {
  "chains": [
    {
      "parameters": {
        "srObj": "{{ $event.srObj }}"
      },
      "chainId": "fetchSRDetailsChangeListener"
    }
  ]
}

Add Input Parameter for the Action Chain and Map Event Object

  1. Navigate to the Action chain created in the previous step and enter the logic as follows:
    1. Create input parameter for event listener "srObj" as 'Any' type and mark as input required from the caller.

    fetchSRDetailsChangeListener.json

    
    "variables": {
      "srObj": {
        "type": "any",
        "input": "fromCaller"
      }
    }

Create a new JS Function and Pass Parameters

  1. Invoke the Call function method and create a new function 'assignFieldsFromSRtoWO' and add the parameters 'srObj' and 'customerWorkOrders' object as shown in the following code sample:
    fetchSRDetailsChangeListener.json
    
    "assignFieldsFromSRtoWO": {
        "module": "vb/action/builtin/callModuleFunctionAction",
        "parameters": {
          "module": "[[ $functions ]]",
          "functionName": "assignFieldsFromSRtoWO",
          "params": [
            "{{ $variables.srObj }}",
            "{{ $base.page.variables.customerWorkOrders }}"
          ]
        }
  2. In the 'assignFieldsFromSRtoWO' function add logic to map the SR object fields to WO object fields and return added WO object from function. The code will look like the following sample:
    create-page-x.js
    
        /**
         * assign Fields from SR to WO Object
         * @param {Object} srObject
         * @param {Object} woObject
         * @return {Object} woObject
         */
        assignFieldsFromSRtoWO(srObject,woObject) {
          woObject.WorkOrderCustText_c = srObject.CustomText_c;       // Add relevant object mapping example : WorkOrderCustText_c is wo custom field where 'CustomText_c' is SR custom field
          return woObject;
        }

Assign Function Result to Work Order Object

  1. Assign 'customerWorkOrders' object to function result obtained from the previous step. The Action chain code will look like the following sample:
fetchSRDetailsChangeListener.json

"actions": {
 "assignVariablesCustomerWorkOrders": {
   "module": "vb/action/builtin/assignVariablesAction",
   "parameters": {
     "$base.page.variables.customerWorkOrders": {
       "source": "{{ $chain.results.assignFieldsFromSRtoWO }}"
     }
   }
 }

Optional Step: If at runtime an error is displayed, for example, 'create-page-template-x.html' not found in browser console:

Navigate to Create page and create a test section to generate 'create-page-template-x.html'. This is required to load the customization page.
  1. Go to the fieldsvc section and find the Create page.
  2. In the page designer, go to the Structure tab and click the Container Ruleset section.
  3. A properties window opens.
  4. Click the CreateFormTemplate link.
  5. In the CreateFormTemplate window, select the option Create Section from the drop-down list.

  6. This step guides you through creating a sample section, which will ultimately generate the file named "create-page-template-x.html".