How to look up doctype value based on parent and use for grid.get_field('field_name').get_query

I have doctypeA (shift attendance), doctypeB (shift name) and doctypeAchild (attendance_details).

doctypeB.name is a link field in doctypeA.

doctypeAchild has a lookup from doctypeC (list of people name) that has to be filtered based on docTypeB.shift_type (doctypeC.shift_category)

I expect to write the below custom script in doctypeA. But can’t figure out how to pull the linked value from docTypeB.shift_type

cur_frm.fields_dict[‘attendance_details’].grid.get_field(‘person_name’).get_query = function(doc, cdt, cdn) {
var child = locals[cdt][cdn];
return {
filters: [
[‘Outsource Contact’, ‘parent’, ‘=’, ‘<>’ ]
]
}
};

Any help will be appreciated.