Script Error

Script Error

I'm trying to write a custom function that will run against incoming requests. It grabs the requesters id, does a GET to grab their information, pulls their managers name and assign that value to a custom field on the request called 'Reporting Manager'.

I'm no expert, but I've managed to put together a script that does that and works in testing, but not when I assign it to an automated process. 

If I do a 'Save and Test' on the custom function, it works without issue and sets the value:


However, if I set it to run as a business rule or custom trigger on a request using the same function, then it throws a 'Invalid JSON Format' error:


Here's the script I've put together: 

manager = '';
returnObj = Collection();
responseGet = Collection();
responsePut = Collection();
configuration = Global_Configuration();

responseGet = invokeurl
[
url: configuration.get('url')+'/api/v3/users/'+requestObj.get('requester').get('id')
type: GET
headers: {'authtoken':configuration.get('technicianKey'),'portalid':context.get('instance').get('id')}
];

if (responseGet.get('response_status').get('status_code') == '2000') {
if (responseGet.get('user').get('reporting_to') != null) {
manager = responseGet.get('user').get('reporting_to').get('name');
responsePut = invokeurl
[
url: configuration.get('url')+'/api/v3/requests/'+requestObj.get('id')
type: put
parameters: {'input_data':{'request':{'udf_fields':{'udf_sline_5702':manager}}}}
headers: {'authtoken':configuration.get('technicianKey'),'portalid':context.get('instance').get('id')}
];
if (responsePut.get('response_status').get('status_code') == '2000') {
returnObj.insert('Result':'Set reporting manager to '+manager);
} else {
returnObj.insert('Result':'Error setting manager to '+manager);
}
} else {
returnObj.insert('Result':'User has no manager');
}
} else {
returnObj.insert('Result':'Error obtaining user');
}
return returnObj;

                  New to ADSelfService Plus?