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.
Create a New Action Chain on VB Enter
- Navigate to
AppUIs tab > Expand Oracle CX Service UI Extension App > Service > fieldsvc > Create page
. - Navigate to
Event Listeners > Create a new Event Listener on VBEnter > Create page Action chain
(with JSON format). For example, vbEnterChangeListener.json
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
- Navigate to the action chain created in the previous step and add this logic:
- Assign 'fetchSRDetails' = true
- Assign 'fetchOtherSRFields' = <SR Field names with coma separated>
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:
"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
- 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
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
- Navigate to the Action chain created in the previous step and enter the logic as
follows:
- 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
- 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 }}" ] }
- 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
- Assign 'customerWorkOrders' object to function result obtained from the previous step. The Action chain code will look like the following sample:
"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:
customization
page.- Go to the
fieldsvc
section and find the Create page. - In the page designer, go to the Structure tab and click the Container Ruleset section.
- A properties window opens.
- Click the CreateFormTemplate link.
-
In the CreateFormTemplate window, select the option Create Section from the drop-down list.
-
This step guides you through creating a sample section, which will ultimately generate the file named "create-page-template-x.html".