Assigned To Value

Hi,
Is there any way that I can get the value of Assigned To in Custom Script?

Use frm.get_docinfo().assignments

Thanks it helped me a lot it shows me the data like.

Now, I have 2 more queries.

  1. Which function will be used to extract the username from the string like substr,left etc.
  2. From where I can learn and find these kind of functions, I appreciate if you can tell me the best resource for the same.

Google is your friend.

The format is a dictionary search and learn about that, for a start go through this Python - Dictionary

Hi,
I have tried but it is not working, I appreciate if you can help me in this regard.

dict=frm.get_docinfo().assignments;
msgprint(dict.get(‘owner’));

use dict.owner

1 Like

Hi Anand,
I have tried it, but it is not working.

dict=frm.get_docinfo().assignments;
msgprint(dict.owner);

No messagebox shown.

As per the python code
frm is an object pointing to the function get_docinfo() of its class and assignments is the dictionary of the function get_docinfo()

I tried to print the owner name using
msgprint(frm.get_docinfo().assignments[‘owner’]);

But it didn’t print anything, can anybody put a light on it?

the data is in JSON format. You have to parse it.

msgprint(JSON.parse(frm.get_docinfo().assignments).owner);

Hi RMehta,

The below code is throwing error on console.

frappe.ui.form.on(“Task”, “refresh”, function(frm){
cur_frm.old_state = frm.doc.workflow_state;
cur_frm.set_value(“task_status”, “In-Process”);
cur_frm.set_value(“assigned”, frm.get_docinfo().assignments);
msgprint(JSON.parse(frm.get_docinfo().assignments).owner);

})

whereas if I remove this line below line from the code it works fine:
msgprint(JSON.parse(frm.get_docinfo().assignments).owner);

Error on the console is:

Try this,

msgprint(frm.get_docinfo().assignments[0].owner).

ref:“Uncaught SyntaxError: Unexpected token o”

1 Like

Great it worked, I appreciate if you can explain me the reason to use it like this.

Output of frm.get_docinfo().assignments is [{“owner":"ruchin78@rediffmail.com”, “description”:“TASK00026”}]. Which is an array, containing dictionary as value at 0th index.
To retrive required dictionary, use it as frm.get_docinfo().assignments[0]

1 Like