Answer:
1. Create a Case saved search through Lists > Support > Cases > Search > click Create Saved Search button.
For the Criteria tab, select all stages:
Filter: Stage
Description: is any of Open, Escalated
For the Results tab:
Sort By: Number - Descending is checked
On the Columns subtab:
Field: Number
2. Click Save and take note of the Saved Search ID.
3. Create a Workflow Action Script. You can do this by navigating to Customization > Scripting > Scripts > New > Workflow Action. You should have the Setup as follow:
Deployments Tab:
Applies To: Case
Deployed: Yes
Status: Released
Parameters Tab:
Return Type: List/Record
List/Record: Case
Upload the script file and script file should have the following contents:
function test_wf_action(){
var recordId = nlapiGetRecordId();
nlapiLogExecution('DEBUG','recordId', recordId);
//Load the current case record
var recs = nlapiLoadRecord('supportcase', recordId);
//Create a new case record
var createRecordReference = nlapiCreateRecord('supportcase');
//Assign the values of the old case record to the new one
createRecordReference = recs;
//Make sure to place the id field as null
createRecordReference.setFieldValue('id', null);
//Reference the saved search we created in step 1.
var searchResultCaseNum = nlapiSearchRecord('supportcase', 'customsearch223', null, null,null);
//If we have Auto-Numbering enabled for Case Records, this will give us the next count.
createRecordReference.setFieldValue('casenumber', searchResultCaseNum[0].getValue(new nlobjSearchColumn('casenumber', null,null)));
nlapiLogExecution('DEBUG','case number', searchResultCaseNum[0].getValue(new nlobjSearchColumn('number', null,null)));
//Submit the new record
var newRecordId = nlapiSubmitRecord(createRecordReference, true, true);
nlapiLogExecution('DEBUG','newRecordId', newRecordId);
//pass the record id and this will be handled by a Workflow
return newRecordId;
}
4. Make sure the Script Deployments of the Workflow Action Script has Execute as Admin checked.
5. Create a Workflow. You can do this by navigating to Customization > Workflow > Workflows > New. You should have the workflow setup shown below:
Workflow Basic Information
Record Type: Case
Execute as Admin: Checked
Release Status: Released
Initiation:
On Update: Before Record Load
Click New State button
State 1:
Actions tab:
Click New Action button
Workflow Action: Add Button
Trigger On: Before Record Load
Label: Save As
Transition to State 2
Button: Save As
Click New State button
State 2
Fields tab:
Click New Field button
Label: Record Internal ID new case
Type: List/Record
List/Record: Case
Store Value: checked
Click Save
Actions:
Workflow Action: Custom Action: [this is the workflow action script we created] Trigger On: Entry Store Result In: Record Internal ID new case <-- this is the Field we created
Workflow Action: Go To Record
Trigger On: Entry
Parameters: Record Type - Case and ID - Record Internal ID new case (State)
Notes:
1. This mimics the Save As button functionality.
2. Only draw back is, the Button created via Workflow is currently also shown in View Mode.
3. A better workaround rather than manually copying the values to a new record.
4. You can modify the workflow action script respectively if you want to set a particular field to blank on the record being created.
No comments:
Post a Comment