JSON Parsing error in custom action script

mickydash2001
Tera Contributor

Can anyone please tell me why I'm getting "Error: o,Detail: Unexpected token: o" this error for below code? here privilaged_user is a Array.Object 

 

privilaged_user = 

[ {
"privileged_user_account_name" : "s5gb78e7rgt5a95070e322fatg9619kl",
"privileged_user_account_type_multi" : "RegularUser",
"privileged_user_email_address" : "aksingh@gmail.com"
} ]

 

and approver is a reference field

 

 

 

(function execute(inputs, outputs) {

  	var mrvs = inputs.privilaged_user;
	mrvs = JSON.parse();

  	var users = mrvs[0].privileged_user_account_name;
        outputs.approver = users.toString;

})(inputs, outputs);

 

 

 

 

 

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

Hi @mickydash2001 ,
I trust you are doing great.

After reviewing the code, it seems like the issue is with the line that contains "mrvs = JSON.parse();". This line is attempting to parse the "mrvs" variable as JSON, but it is missing the argument that specifies the JSON string to be parsed.

To fix this issue, you should pass the "mrvs" variable as an argument to the JSON.parse() function, like this:

mrvs = JSON.parse(mrvs);

Additionally, there are a few other issues with the code that need to be addressed. Here is the updated code with these fixes:

(function execute(inputs, outputs) {
  var privileged_users = inputs.privilaged_user;
  var users = privileged_users[0].privileged_user_account_name;
  outputs.approver = users.toString();
})(inputs, outputs);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

4 REPLIES 4

Joshua_Quinn
Kilo Guru

In my experience, an array with JSON inside of it does not parse the JSON object when calling the parse on the array. Please try this and see if you get the same error: 

 

(function execute(inputs, outputs) {

	var mrvs = inputs.privilaged_user;
	mrvs = JSON.parse(mrvs);

	var user_object = JSON.parse(mrvs[0]);
	var users = user_object.privileged_user_account_name;
	outputs.approver = users.toString;

})(inputs, outputs);

Edited: I noticed you weren't parsing anything, so I edited the mrvs line to run the parse on the mrvs.

 

Hi @Joshua_Quinn ,

Thanks for the reply.

I tried this solution still facing the same error. Is there anything else I can modify?

Amit Gujarathi
Giga Sage
Giga Sage

Hi @mickydash2001 ,
I trust you are doing great.

After reviewing the code, it seems like the issue is with the line that contains "mrvs = JSON.parse();". This line is attempting to parse the "mrvs" variable as JSON, but it is missing the argument that specifies the JSON string to be parsed.

To fix this issue, you should pass the "mrvs" variable as an argument to the JSON.parse() function, like this:

mrvs = JSON.parse(mrvs);

Additionally, there are a few other issues with the code that need to be addressed. Here is the updated code with these fixes:

(function execute(inputs, outputs) {
  var privileged_users = inputs.privilaged_user;
  var users = privileged_users[0].privileged_user_account_name;
  outputs.approver = users.toString();
})(inputs, outputs);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



@Amit Gujarathi Thanks for the solution. The issue got resolved.