Hello, I have a business rule set up to run a Custom Function when a ticket is created through email. I want to change the contents of certain fields based on the subject of the email.
- Mode
- An Additional Pick List
- An Additional Sline
- Category/Subcategory/Item
The docs for this (https://help.servicedeskplus.com/request-custom-function) Say: "Changes that are made to 'requestObj' values will be updated in the request on which the automation rule acts. " however this doesn't seem to be the case. My code never updates the fields and gives errors in the history of the ticket. I stripped my code down to just update one field to figure out why it's not working.
- udf_field_api_name = "udf_pick_7202";
- new_value = "Valley Fiber";
- requestObj.put("udf_fields", {udf_field_api_name : new_value});
- return requestObj;
and here is the error I see in the ticket that was created by the business rule:
- Change Company: To Valley Fiber - Executed from business rule id 6902. Result : Execution failed Message : sdp.custom.script.improper.json
I have also tried this method: https://pitstop.manageengine.com/portal/en/kb/articles/update-request-additional-fields-during-request-create-update-using-business-rules
My Code:
- udf_field_api_name = "udf_pick_7202";
- new_value = "Valley Fiber";
- returnjson = {
- "operation": [{
- "INPUT_DATA": [{
- "request": {
- "udf_fields": {
- udf_field_api_name: {"value": new_value}
- }
- }
- }],
- "OPERATIONNAME": "UPDATE",
- "FORMAT": "V3"
- }],
- "result": "success",
- "message": "Additional field updated successfully!!"
- };
- return returnjson;
This gives me this error:
- Change Company: To Valley Fiber (API) - Executed from business rule id 6902. Result : Execution failed Message : {"status_code":4000,"messages":[{"status_code":4012,"field":"udf_fields","type":"failed","message":"Value not provided"}],"status":"failed"}
Why doesn't this work? I based it on the example found in your documentation. I would really appreciate any help figuring out where I went wrong! Thank you.
EDIT: Update
These are the two custom functions I have now:
- description = requestObj.get("description");
- if(description.contains("A voice message was left from")) {
- requesturl = "http://helpdesk.vispnet.ca:8080/api/v3/requests/" + requestObj.get("id");
- input_data = {
- "request": {
- "mode": {
- "name": "Phone Call",
- "id": "3"
- }
- }
- };
- response = invokeurl
- [
- url: requesturl
- type: PUT
- parameters: {"input_data":input_data}
- headers: {"authtoken":"myauthtoken","PORTALID": "1"}
- ];
- returnObj = Collection();
- if(response.get("response_status").get("status_code") == 2000) {
- returnObj.insert("result":"Success","message":"Status Updated!");
- }
- else{
- returnObj.insert("result":"failure","message":"Error occured changing the request. Code: " + response.get("response_status").get("status_code") + response.get("response_status").get("description") );
- }
- }//endif
- //info "request mode is " + requestObj.get("mode");
- return returnObj;
and
- //Get basic request info
- requesturl = "http://helpdesk.vispnet.ca:8080/api/v3/requests/" + requestObj.get("id");
- requestSubject = requestObj.get("subject");
- //debug
- //info requestObj.get("id") + " " + requestSubject;
- //Set up variables to change
- company = "No Company Provided";
- impactedService = "(No Impacted Service Provided)";
- category = null;
- subcategory = null;
- item = null;
- //--Set up defaults for Cat/SubCat/Item to reduce repetition
- //Internet
- internetCategory = {
- "name": "No Internet",
- "id": "1504"
- };
- internetSubcategory = {
- "name": "Known Issue",
- "id": "2701"
- };
- //---End Defaults
- if ( requestSubject.contains("Valley Fiber") || requestSubject.contains("VF")) {
- company = "Valley Fiber";
- impactedService = "Internet";
- category = internetCategory;
- subcategory = internetSubcategory;
- } else if (requestSubject.contains("VISP")){
- company = "VISP";
- impactedService = "Internet";
- category = internetCategory;
- subcategory = internetSubcategory;
- } else if (requestSubject.contains("VFTV") || requestSubject.contains("TV") || requestSubject.contains("IPTV")) {
- company = "VFTV";
- impactedService = "TV";
- }
- subjectString = "Known Impact - ".concat(company).concat(" - ").concat(impactedService);
- input_data = {
- "request": {
- "subject": subjectString,
- "category": category,
- "subcategory": subcategory,
- "item": item,
- "udf_fields": {
- "udf_sline_6001": company
- }
- }
- };
- //TODO add category, subcat, and item to api call
- response = invokeurl
- [
- url: requesturl
- type: PUT
- parameters: {"input_data":input_data}
- headers: {"authtoken":"myauthtoken","PORTALID": "1"}
- ];
- returnObj = Collection();
- if(response.get("response_status").get("status_code") == 2000) {
- returnObj.insert("result":"Success","message":"Status Updated!");
- }
- else{
- returnObj.insert("result":"failure","message":"Error occured changing the request. Code: " + response.get("response_status").get("status_code") );
- }
- return returnObj;
And it updates the request properly when I use 'save and test', however running the same code gives errors when triggered through a business rule:
Why does my code work in save and test, but not when triggered by a business rule? here's how one of the business rules is configured: