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.
- Which function will be used to extract the username from the string like substr,left etc.
- 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
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).
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]